Commit 58848cbe authored by Philipp Schafft's avatar Philipp Schafft 🦁

Feature: Allow listen sockets to be of type "virtual"

parent 75be23b5
...@@ -178,6 +178,8 @@ static listener_type_t config_str_to_listener_type(const char *str) ...@@ -178,6 +178,8 @@ static listener_type_t config_str_to_listener_type(const char *str)
return LISTENER_TYPE_NORMAL; return LISTENER_TYPE_NORMAL;
} else if (strcasecmp(str, "normal") == 0) { } else if (strcasecmp(str, "normal") == 0) {
return LISTENER_TYPE_NORMAL; return LISTENER_TYPE_NORMAL;
} else if (strcasecmp(str, "virtual") == 0) {
return LISTENER_TYPE_VIRTUAL;
} else { } else {
ICECAST_LOG_ERROR("Unknown listener type \"%s\", falling back to NORMAL.", str); ICECAST_LOG_ERROR("Unknown listener type \"%s\", falling back to NORMAL.", str);
return LISTENER_TYPE_NORMAL; return LISTENER_TYPE_NORMAL;
......
...@@ -148,7 +148,9 @@ typedef struct _resource { ...@@ -148,7 +148,9 @@ typedef struct _resource {
} resource_t; } resource_t;
typedef enum _listener_type_tag { typedef enum _listener_type_tag {
LISTENER_TYPE_NORMAL LISTENER_TYPE_ERROR,
LISTENER_TYPE_NORMAL,
LISTENER_TYPE_VIRTUAL
} listener_type_t; } listener_type_t;
typedef struct _listener_t { typedef struct _listener_t {
......
...@@ -290,13 +290,19 @@ int listensocket_container_setup(listensocket_container_ ...@@ -290,13 +290,19 @@ int listensocket_container_setup(listensocket_container_
} }
static int listensocket_container_setup__unlocked(listensocket_container_t *self) static int listensocket_container_setup__unlocked(listensocket_container_t *self)
{ {
listener_type_t type;
size_t i; size_t i;
int ret = 0; int ret = 0;
for (i = 0; i < self->sock_len; i++) { for (i = 0; i < self->sock_len; i++) {
if (self->sockref[i]) { listensocket_apply_config(self->sock[i]);
listensocket_apply_config(self->sock[i]);
} else { type = listensocket_get_type(self->sock[i]);
if (self->sockref[i] && type == LISTENER_TYPE_VIRTUAL) {
if (listensocket_unrefsock(self->sock[i]) == 0) {
self->sockref[i] = 0;
}
} else if (!self->sockref[i] && type != LISTENER_TYPE_VIRTUAL) {
if (listensocket_refsock(self->sock[i]) == 0) { if (listensocket_refsock(self->sock[i]) == 0) {
self->sockref[i] = 1; self->sockref[i] = 1;
} else { } else {
...@@ -540,10 +546,12 @@ static int listensocket_apply_config__unlocked(listensocket_t *self ...@@ -540,10 +546,12 @@ static int listensocket_apply_config__unlocked(listensocket_t *self
listener = self->listener; listener = self->listener;
} }
if (listener->so_sndbuf) if (self->sock != SOCK_ERROR) {
sock_set_send_buffer(self->sock, listener->so_sndbuf); if (listener->so_sndbuf)
sock_set_send_buffer(self->sock, listener->so_sndbuf);
sock_set_blocking(self->sock, 0); sock_set_blocking(self->sock, 0);
}
if (self->listener_update) { if (self->listener_update) {
while ((self->listener = config_clear_listener(self->listener))); while ((self->listener = config_clear_listener(self->listener)));
...@@ -706,6 +714,20 @@ int listensocket_release_listener(listensocket_t *self) ...@@ -706,6 +714,20 @@ int listensocket_release_listener(listensocket_t *self)
return 0; return 0;
} }
listener_type_t listensocket_get_type(listensocket_t *self)
{
listener_type_t ret;
if (!self)
return LISTENER_TYPE_ERROR;
thread_mutex_lock(&self->lock);
ret = self->listener->type;
thread_mutex_unlock(&self->lock);
return ret;
}
#ifdef HAVE_POLL #ifdef HAVE_POLL
static inline int listensocket__poll_fill(listensocket_t *self, struct pollfd *p) static inline int listensocket__poll_fill(listensocket_t *self, struct pollfd *p)
{ {
......
...@@ -25,5 +25,6 @@ int listensocket_unrefsock(listensocket_t *self); ...@@ -25,5 +25,6 @@ int listensocket_unrefsock(listensocket_t *self);
connection_t * listensocket_accept(listensocket_t *self); connection_t * listensocket_accept(listensocket_t *self);
const listener_t * listensocket_get_listener(listensocket_t *self); const listener_t * listensocket_get_listener(listensocket_t *self);
int listensocket_release_listener(listensocket_t *self); int listensocket_release_listener(listensocket_t *self);
listener_type_t listensocket_get_type(listensocket_t *self);
#endif #endif
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