summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--announce.c9
-rw-r--r--main.c13
-rw-r--r--main.h1
3 files changed, 17 insertions, 6 deletions
diff --git a/announce.c b/announce.c
index 673d649..13ef423 100644
--- a/announce.c
+++ b/announce.c
@@ -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;
}
diff --git a/main.c b/main.c
index 111ea33..fd6b2aa 100644
--- a/main.c
+++ b/main.c
@@ -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);
diff --git a/main.h b/main.h
index af21ece..8c265ca 100644
--- a/main.h
+++ b/main.h
@@ -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;