diff options
Diffstat (limited to 'announce.c')
-rw-r--r-- | announce.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -5,6 +5,7 @@ #include <arpa/inet.h> #include <string.h> #include <unistd.h> +#include <time.h> #include "main.h" #include "uring.h" @@ -15,6 +16,7 @@ struct announce { uint64_t value; struct uring_task task; int mcast_fd; + time_t until; }; static void @@ -31,9 +33,15 @@ announce_cb(struct uring_task *task, int res) return; } - debug(DBG_ANN, "timerfd value %" PRIu64, announce->value); - list_for_each_entry(server, &cfg->servers, list) - server_announce(server, announce->mcast_fd); + if (announce->until != 0 && time(NULL) > announce->until) { + debug(DBG_ANN, "stopping announcements"); + announce_stop(); + } else { + debug(DBG_ANN, "announcing servers"); + list_for_each_entry(server, &cfg->servers, list) + server_announce(server, announce->mcast_fd); + } + uring_read(&announce->task, &announce->value, sizeof(announce->value), announce_cb); } @@ -88,7 +96,7 @@ announce_stop() } void -announce_start() +announce_start(unsigned duration) { struct itimerspec tspec = { .it_interval = { @@ -103,6 +111,11 @@ announce_start() assert_return(cfg->announce); + if (duration > 0) + cfg->announce->until = time(NULL) + duration; + else + cfg->announce->until = 0; + if (timerfd_settime(cfg->announce->task.fd, 0, &tspec, NULL) != 0) error("timerfd_settime: %m"); } |