1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-16 06:15:24 +00:00

Feature: Added support to set listen(2) backlog.

Closes: #2225
This commit is contained in:
Philipp Schafft 2018-09-28 13:52:39 +00:00
parent dd967ad17b
commit de6e8b4197
3 changed files with 21 additions and 1 deletions

View File

@ -1911,6 +1911,8 @@ static void _parse_listen_socket(xmlDocPtr doc,
node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("so-sndbuf")) == 0) {
__read_int(doc, node, &listener->so_sndbuf, "<so-sndbuf> must not be empty.");
} else if (xmlStrcmp(node->name, XMLSTR("listen-backlog")) == 0) {
__read_int(doc, node, &listener->listen_backlog, "<listen-backlog> must not be empty.");
} else if (xmlStrcmp(node->name, XMLSTR("authentication")) == 0) {
_parse_authentication_node(node, &(listener->authstack));
}
@ -2629,6 +2631,7 @@ listener_t *config_copy_listener_one(const listener_t *listener) {
n->next = NULL;
n->port = listener->port;
n->so_sndbuf = listener->so_sndbuf;
n->listen_backlog = listener->listen_backlog;
n->type = listener->type;
n->id = (char*)xmlStrdup(XMLSTR(listener->id));
if (listener->on_behalf_of) {

View File

@ -161,6 +161,7 @@ typedef struct _listener_t {
listener_type_t type;
int port;
int so_sndbuf;
int listen_backlog;
char *bind_address;
int shoutcast_compat;
char *shoutcast_mount;

View File

@ -73,6 +73,20 @@ static inline const char * __string_default(const char *str, const char *def)
return str != NULL ? str : def;
}
static inline int __socket_listen(sock_t serversock, const listener_t *listener)
{
int listen_backlog = listener->listen_backlog;
if (listen_backlog < 1)
listen_backlog = ICECAST_LISTEN_QUEUE;
if (listen_backlog > 128) {
listen_backlog = 128;
ICECAST_LOG_WARN("Listen backlog for listen socket on %s port %i is set insanely high. Limiting to sane range.", __string_default(listener->bind_address, "<ANY>"), listener->port);
}
return sock_listen(serversock, listen_backlog);
}
static inline int __listener_cmp(const listener_t *a, const listener_t *b)
{
if (a == b)
@ -581,6 +595,8 @@ static int listensocket_apply_config__unlocked(listensocket_t *self
sock_set_send_buffer(self->sock, listener->so_sndbuf);
sock_set_blocking(self->sock, 0);
__socket_listen(self->sock, listener);
}
if (self->listener_update) {
@ -632,7 +648,7 @@ int listensocket_refsock(listensocket_t *self)
return -1;
}
if (sock_listen(self->sock, ICECAST_LISTEN_QUEUE) == 0) {
if (__socket_listen(self->sock, self->listener) == 0) {
sock_close(self->sock);
self->sock = SOCK_ERROR;
thread_rwlock_rlock(&self->listener_rwlock);