From 83f51fe9654c97248e530b49f6b28a5a58f3aeeb Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 4 Feb 2017 16:28:35 +0100 Subject: [PATCH] gossip: Add timer support to the io_loop --- lightningd/gossip/Makefile | 2 +- lightningd/gossip/gossip.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lightningd/gossip/Makefile b/lightningd/gossip/Makefile index 57965ad20..ab19c656a 100644 --- a/lightningd/gossip/Makefile +++ b/lightningd/gossip/Makefile @@ -16,7 +16,7 @@ LIGHTNINGD_GOSSIP_CONTROL_OBJS := $(LIGHTNINGD_GOSSIP_CONTROL_SRC:.c=.o) # These should eventually be migrated to the lightningd directory, after # deprecating the legacy daemons LIGHTNINGD_GOSSIP_LEGACY_HEADERS := daemon/routing.h daemon/broadcast.h \ - daemon/log.h daemon/pseudorand.h + daemon/log.h daemon/pseudorand.h daemon/timeout.h # lightningd/gossip needs these: LIGHTNINGD_GOSSIP_HEADERS := lightningd/gossip/gen_gossip_control_wire.h \ diff --git a/lightningd/gossip/gossip.c b/lightningd/gossip/gossip.c index 68edfd028..927d22c59 100644 --- a/lightningd/gossip/gossip.c +++ b/lightningd/gossip/gossip.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,8 @@ struct daemon { /* Routing information */ struct routing_state *rstate; + + struct timers timers; }; struct peer { @@ -355,13 +358,24 @@ int main(int argc, char *argv[]) daemon = tal(NULL, struct daemon); daemon->rstate = new_routing_state(daemon, NULL); list_head_init(&daemon->peers); + timers_init(&daemon->timers, time_mono()); daemon->msg_in = NULL; /* Stdout == status, stdin == requests */ status_setup(STDOUT_FILENO); io_new_conn(NULL, STDIN_FILENO, next_req_in, daemon); - io_loop(NULL, NULL); + + for (;;) { + struct timer *expired = NULL; + io_loop(&daemon->timers, &expired); + + if (!expired) { + break; + } else { + timer_expired(daemon, expired); + } + } tal_free(daemon); return 0;