From 39e8956d056b6b3cb886cdc2ff7eae8b07b53fcc Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Mon, 22 Jun 2020 13:40:00 +0200 Subject: Properly hook up igmp with announce --- announce.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'announce.c') diff --git a/announce.c b/announce.c index 17ab2bb..2510d5d 100644 --- a/announce.c +++ b/announce.c @@ -5,6 +5,7 @@ #include #include #include +#include #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"); } -- cgit v1.2.3