summaryrefslogtreecommitdiff
path: root/announce.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-22 13:40:00 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-22 13:40:00 +0200
commit39e8956d056b6b3cb886cdc2ff7eae8b07b53fcc (patch)
tree5d9741121a414a29450357388eb9b70270ce59d3 /announce.c
parent6a0ce89e1110cb49ed1c00bec2d96073b9378cb3 (diff)
Properly hook up igmp with announce
Diffstat (limited to 'announce.c')
-rw-r--r--announce.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/announce.c b/announce.c
index 17ab2bb..2510d5d 100644
--- a/announce.c
+++ b/announce.c
@@ -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");
}