Commit 34c62036 authored by Jack Moffitt's avatar Jack Moffitt

Add a source-timeout config option and implement it. This prevents lame

sources from sticking around way too long.  Default is 10 seconds.

svn path=/trunk/icecast/; revision=2968
parent 4d079ba4
......@@ -6,7 +6,9 @@
<clients>100</clients>
<sources>2</sources>
<threadpool>5</threadpool>
<client-timeout>15</client-timeout>
<client-timeout>30</client-timeout>
<header-timeout>15</header-timeout>
<source-timeout>10</source-timeout>
</limits>
<source-password>hackme</source-password>
......
......@@ -12,6 +12,7 @@
#define CONFIG_DEFAULT_THREADPOOL_SIZE 4
#define CONFIG_DEFAULT_CLIENT_TIMEOUT 30
#define CONFIG_DEFAULT_HEADER_TIMEOUT 15
#define CONFIG_DEFAULT_SOURCE_TIMEOUT 10
#define CONFIG_DEFAULT_SOURCE_PASSWORD "changeme"
#define CONFIG_DEFAULT_TOUCH_FREQ 5
#define CONFIG_DEFAULT_HOSTNAME "localhost"
......@@ -119,6 +120,7 @@ static void _set_defaults(void)
_configuration.threadpool_size = CONFIG_DEFAULT_THREADPOOL_SIZE;
_configuration.client_timeout = CONFIG_DEFAULT_CLIENT_TIMEOUT;
_configuration.header_timeout = CONFIG_DEFAULT_HEADER_TIMEOUT;
_configuration.source_timeout = CONFIG_DEFAULT_SOURCE_TIMEOUT;
_configuration.source_password = (char *)strdup(CONFIG_DEFAULT_SOURCE_PASSWORD);
_configuration.touch_freq = CONFIG_DEFAULT_TOUCH_FREQ;
_configuration.dir_list = NULL;
......@@ -198,6 +200,10 @@ static void _parse_limits(xmlDocPtr doc, xmlNodePtr node)
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
_configuration.header_timeout = atoi(tmp);
if (tmp) free(tmp);
} else if (strcmp(node->name, "source-timeout") == 0) {
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
_configuration.source_timeout = atoi(tmp);
if (tmp) free(tmp);
}
} while ((node = node->next));
}
......
......@@ -22,6 +22,7 @@ typedef struct ice_config_tag
int threadpool_size;
int client_timeout;
int header_timeout;
int source_timeout;
char *source_password;
......
......@@ -24,6 +24,7 @@
#include "stats.h"
#include "format.h"
#include "logging.h"
#include "config.h"
#include "source.h"
......@@ -106,6 +107,7 @@ void *source_main(void *arg)
source_t *source = (source_t *)arg;
char buffer[4096];
long bytes, sbytes;
int ret, timeout;
client_t *client;
avl_node *client_node;
......@@ -117,6 +119,8 @@ void *source_main(void *arg)
int listeners = 0;
timeout = config_get_config()->source_timeout;
/* grab a read lock, to make sure we get a chance to cleanup */
thread_rwlock_rlock(source->shutdown_rwlock);
......@@ -138,10 +142,15 @@ void *source_main(void *arg)
while (bytes <= 0) {
FD_ZERO(&rfds);
FD_SET(source->con->sock, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 30000;
select(source->con->sock + 1, &rfds, NULL, NULL, &tv);
tv.tv_sec = timeout;
tv.tv_usec = 0;
ret = select(source->con->sock + 1, &rfds, NULL, NULL, &tv);
if (ret == 0) { /* timeout expired */
bytes = 0;
break;
}
bytes = sock_read_bytes(source->con->sock, buffer, 4096);
if (bytes == 0 || (bytes < 0 && !sock_recoverable(sock_error()))) break;
......
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