diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-22 22:13:26 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-22 22:13:26 +0200 |
commit | c66ab06124fd757056817b38a9c16f8c8444bf0a (patch) | |
tree | c7fc33b7608f28d4e8334af2da6c12d1843a3468 | |
parent | 9295a00a976df83d2c35a6dc56ceb35c05f692dd (diff) |
Make announce interval a config option
-rw-r--r-- | announce.c | 9 | ||||
-rw-r--r-- | main.c | 13 | ||||
-rw-r--r-- | main.h | 1 |
3 files changed, 17 insertions, 6 deletions
@@ -18,8 +18,6 @@ struct announce { int mcast_fd; }; -#define ANNOUNCE_INTERVAL 3 - static void announce_cb(struct ptimer_task *ptask) { @@ -57,7 +55,7 @@ announce_refdump() void announce_delete() { - assert_return(cfg->announce); + assert_return_silent(cfg->announce); debug(DBG_ANN, "called"); announce_stop(); @@ -87,7 +85,7 @@ announce_start(unsigned duration) times = 0; else times = MAX(announce->ptask.times, - DIV_ROUND_UP(duration, ANNOUNCE_INTERVAL)); + DIV_ROUND_UP(duration, cfg->announce_interval)); announce->ptask.times = times; ptimer_add_task(&announce->ptask); @@ -100,6 +98,7 @@ announce_init() int sfd; assert_return(!cfg->announce); + assert_return_silent(cfg->announce_interval > 0); announce = zmalloc(sizeof(*announce)); if (!announce) @@ -110,7 +109,7 @@ announce_init() die("socket: %m"); uring_task_init(&announce->task, "announce", uring_parent(), announce_free); - ptask_init(&announce->ptask, ANNOUNCE_INTERVAL, 0, announce_cb); + ptask_init(&announce->ptask, cfg->announce_interval, 0, announce_cb); announce->mcast_fd = sfd; cfg->announce = announce; } @@ -31,6 +31,7 @@ #define DEFAULT_HOMEDIR_PATH "/home/david/intest" #define DEFAULT_MAIN_CONFIG_FILE_PATH "./mcproxy.conf" +#define DEFAULT_ANNOUNCE_INTERVAL 3 /* Global */ struct cfg *cfg = NULL; @@ -196,7 +197,8 @@ cfg_free(struct uring_task *task) enum mcfg_keys { MCFG_KEY_INVALID = 0, MCFG_KEY_IGMP, - MCFG_KEY_IGMP_IFACE + MCFG_KEY_IGMP_IFACE, + MCFG_KEY_ANN_INTERVAL, }; struct cfg_key_value_map mcfg_key_map[] = { @@ -209,6 +211,10 @@ struct cfg_key_value_map mcfg_key_map[] = { .key_value = MCFG_KEY_IGMP_IFACE, .value_type = CFG_VAL_TYPE_STRING, }, { + .key_name = "announce_interval", + .key_value = MCFG_KEY_ANN_INTERVAL, + .value_type = CFG_VAL_TYPE_UINT16, + }, { .key_name = NULL, .key_value = MCFG_KEY_INVALID, .value_type = CFG_VAL_TYPE_INVALID, @@ -293,6 +299,10 @@ cfg_read() break; + case MCFG_KEY_ANN_INTERVAL: + cfg->announce_interval = value.uint16; + break; + case MCFG_KEY_INVALID: default: die("main config file (%s) invalid", path); @@ -387,6 +397,7 @@ cfg_init(int argc, char **argv) if (!cfg) die("malloc: %m"); + cfg->announce_interval = DEFAULT_ANNOUNCE_INTERVAL; cfg->uid = geteuid(); cfg->gid = getegid(); uring_task_init(&cfg->task, "main", NULL, cfg_free); @@ -148,6 +148,7 @@ struct cfg { bool do_igmp; char *igmp_iface; bool splice_supported; + uint16_t announce_interval; struct uring_ev *uring; struct server_cfg_monitor *server_cfg_monitor; |