campaignd: Replace write_config() scheduling mechanism

Check time() deltas instead of incrementing a counter variable forever.
This should allow to extract a bit of the run() logic into a separate
method later.
This commit is contained in:
Ignacio R. Morelle 2014-06-07 16:55:04 -04:00
parent deea32f9a5
commit a8ea4796a0

View File

@ -361,7 +361,9 @@ void server::run()
network::connection sock = 0;
for(int increment = 0;; ++increment)
time_t last_ts = time(NULL);
for(;;)
{
try {
std::string admin_cmd;
@ -373,9 +375,12 @@ void server::run()
break;
}
}
//write config to disk every ten minutes
if((increment%(60*10*50)) == 0) {
const time_t cur_ts = time(NULL);
// Write config to disk every ten minutes.
if(cur_ts - last_ts >= 60) {
write_config();
last_ts = cur_ts;
}
network::process_send_queue();