diff --git a/src/net.c b/src/net.c index 7758d9da..779a45de 100644 --- a/src/net.c +++ b/src/net.c @@ -511,13 +511,29 @@ void retry(void) { timeout_set(&pingtimer, &(struct timeval){0, 0}); } +/* + Initialize timers +*/ +void init_timers(void) { + timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval){pingtimeout, rand() % 100000}); + timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){0, 0}); +} + +/* + Release timers +*/ + +void exit_timers(void) { + timeout_del(&periodictimer); + timeout_del(&pingtimer); +} + /* this is where it all happens... */ int main_loop(void) { last_periodic_run_time = now; - timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval){pingtimeout, rand() % 100000}); - timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){0, 0}); + init_timers(); #ifndef HAVE_MINGW signal_t sighup; @@ -552,8 +568,6 @@ int main_loop(void) { signal_del(&sigalrm); #endif - timeout_del(&periodictimer); - timeout_del(&pingtimer); - + exit_timers(); return 0; } diff --git a/src/net.h b/src/net.h index c84002ec..e39c7877 100644 --- a/src/net.h +++ b/src/net.h @@ -220,6 +220,8 @@ extern void regenerate_key(void); extern void update_edge_weight(void); extern void purge(void); extern void retry(void); +extern void init_timers(void); +extern void exit_timers(void); extern int reload_configuration(void); extern void load_all_nodes(void); extern void try_tx(struct node_t *n, bool);