More reliable file load/save

pull/206/head
SChernykh 2 years ago
parent f044149004
commit ed78e9df6e

@ -477,6 +477,7 @@ void P2PServer::save_peer_list()
}
}
f.flush();
f.close();
LOGINFO(5, "peer list saved (" << peer_list.size() << " peers)");
@ -557,7 +558,7 @@ void P2PServer::load_peer_list()
std::ifstream f(saved_peer_list_file_name);
if (f.is_open()) {
std::string address;
while (!f.eof()) {
while (f.good()) {
std::getline(f, address);
if (!address.empty()) {
if (!saved_list.empty()) {

@ -826,25 +826,26 @@ void p2pool::load_found_blocks()
return;
}
while (!f.eof()) {
while (f.good()) {
time_t timestamp;
f >> timestamp;
if (f.eof()) break;
if (!f.good()) break;
uint64_t height;
f >> height;
if (f.eof()) break;
if (!f.good()) break;
hash id;
f >> id;
if (f.eof()) break;
if (!f.good()) break;
difficulty_type block_difficulty;
f >> block_difficulty;
if (f.eof()) break;
if (!f.good()) break;
difficulty_type cumulative_difficulty;
f >> cumulative_difficulty;
if (!f.good() && !f.eof()) break;
m_foundBlocks.emplace_back(timestamp, height, id, block_difficulty, cumulative_difficulty);
}
@ -1333,6 +1334,8 @@ void p2pool::api_update_block_found(const ChainMain* data)
std::ofstream f(FOUND_BLOCKS_FILE, std::ios::app);
if (f.is_open()) {
f << cur_time << ' ' << data->height << ' ' << data->id << ' ' << diff << ' ' << total_hashes << '\n';
f.flush();
f.close();
}
}

Loading…
Cancel
Save