Commit 9afc1026 authored by Philipp Schafft's avatar Philipp Schafft

Feature: Allow complete reconfiguration of sockets on config reload

parent ae2d9546
Pipeline #145 passed with stage
in 46 seconds
......@@ -147,13 +147,7 @@ void connection_shutdown(void)
void connection_reread_config(struct ice_config_tag *config)
{
get_tls_certificate(config);
/* This does not work yet.
* listensocket_container_configure() should keep sockets that are the same.
* Otherwise the Kernel doesn't let us do it.
* -- ph3-der-loewe, 2018-04-17
listensocket_container_configure(global.listensockets, config);
listensocket_container_setup(global.listensockets);
*/
listensocket_container_configure_and_setup(global.listensockets, config);
}
static unsigned long _next_connection_id(void)
......
......@@ -38,11 +38,13 @@ struct listensocket_tag {
size_t refc;
size_t sockrefc;
listener_t *listener;
listener_t *listener_update;
sock_t sock;
};
static listensocket_t * listensocket_new(const listener_t *listener);
static int listensocket_apply_config(listensocket_t *self, const listener_t *listener);
static int listensocket_apply_config(listensocket_t *self);
static int listensocket_set_update(listensocket_t *self, const listener_t *listener);
#ifdef HAVE_POLL
static inline int listensocket__poll_fill(listensocket_t *self, struct pollfd *p);
#else
......@@ -147,11 +149,35 @@ int listensocket_container_unref(listensocket_container_
return 0;
}
static inline void __find_matching_entry(listensocket_container_t *self, const listener_t *listener, listensocket_t ***found, int **ref)
{
const listener_t *b;
size_t i;
for (i = 0; i < self->sock_len; i++) {
if (self->sock[i] != NULL) {
if (self->sockref[i]) {
b = listensocket_get_listener(self->sock[i]);
if (__listener_cmp(listener, b) == 1) {
*found = &(self->sock[i]);
*ref = &(self->sockref[i]);
return;
}
}
}
}
*found = NULL;
*ref = NULL;
}
int listensocket_container_configure(listensocket_container_t *self, const ice_config_t *config)
{
listensocket_t **n;
listensocket_t **match;
listener_t *cur;
int *r;
int *m;
size_t i;
if (!self || !config)
......@@ -173,7 +199,16 @@ int listensocket_container_configure(listensocket_contai
cur = config->listen_sock;
for (i = 0; i < config->listen_sock_count; i++) {
if (cur) {
n[i] = listensocket_new(cur);
__find_matching_entry(self, cur, &match, &m);
if (match) {
n[i] = *match;
r[i] = 1;
*match = NULL;
*m = 0;
listensocket_set_update(n[i], cur);
} else {
n[i] = listensocket_new(cur);
}
} else {
n[i] = NULL;
}
......@@ -227,14 +262,15 @@ int listensocket_container_setup(listensocket_container_
return -1;
for (i = 0; i < self->sock_len; i++) {
if (self->sockref[i])
continue;
if (listensocket_refsock(self->sock[i]) == 0) {
self->sockref[i] = 1;
if (self->sockref[i]) {
listensocket_apply_config(self->sock[i]);
} else {
ICECAST_LOG_DEBUG("Can not ref socket.");
ret = 1;
if (listensocket_refsock(self->sock[i]) == 0) {
self->sockref[i] = 1;
} else {
ICECAST_LOG_DEBUG("Can not ref socket.");
ret = 1;
}
}
}
......@@ -414,33 +450,32 @@ int listensocket_unref(listensocket_t *self)
}
while ((self->listener = config_clear_listener(self->listener)));
while ((self->listener_update = config_clear_listener(self->listener_update)));
free(self);
return 0;
}
static int listensocket_apply_config(listensocket_t *self, const listener_t *listener)
static int listensocket_apply_config(listensocket_t *self)
{
listener_t *copy = NULL;
const listener_t *listener;
if (!self || !listener)
if (!self)
return -1;
if (listener != self->listener) {
if (__listener_cmp(listener, self->listener) != 1) {
if (self->listener_update) {
if (__listener_cmp(self->listener, self->listener_update) != 1) {
ICECAST_LOG_ERROR("Tried to apply incomplete configuration to listensocket: bind address missmatch: have %s:%i, got %s:%i",
__string_default(self->listener->bind_address, "<ANY>"),
self->listener->port,
__string_default(listener->bind_address, "<ANY>"),
listener->port
__string_default(self->listener_update->bind_address, "<ANY>"),
self->listener_update->port
);
return -1;
}
copy = config_copy_listener_one(listener);
if (copy == NULL) {
ICECAST_LOG_ERROR("Can not copy listen socket configuration");
return -1;
}
listener = self->listener_update;
} else {
listener = self->listener;
}
if (listener->so_sndbuf)
......@@ -448,14 +483,31 @@ static int listensocket_apply_config(listensocket_t *self, const li
sock_set_blocking(self->sock, 0);
if (copy != NULL) {
if (self->listener_update) {
while ((self->listener = config_clear_listener(self->listener)));
self->listener = copy;
self->listener = self->listener_update;
self->listener_update = NULL;
}
return 0;
}
static int listensocket_set_update(listensocket_t *self, const listener_t *listener)
{
listener_t *n;
if (!self || !listener)
return -1;
n = config_copy_listener_one(listener);
if (n == NULL)
return -1;
while ((self->listener_update = config_clear_listener(self->listener_update)));
self->listener_update = n;
return 0;
}
int listensocket_refsock(listensocket_t *self)
{
if (!self)
......@@ -477,7 +529,7 @@ int listensocket_refsock(listensocket_t *self)
return -1;
}
if (listensocket_apply_config(self, self->listener) == -1)
if (listensocket_apply_config(self) == -1)
return -1;
self->sockrefc++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment