Add write timeout of 30s to all TCP server operations, this is further reduced to 5s for streaming output. Fixes #1054.

This commit is contained in:
Adam Sutton 2012-08-30 16:45:43 +01:00
parent 7232388db4
commit b2b15cb60a
2 changed files with 9 additions and 0 deletions

View file

@ -370,6 +370,7 @@ static void *
tcp_server_start(void *aux)
{
tcp_server_launch_t *tsl = aux;
struct timeval to;
int val;
val = 1;
@ -393,6 +394,9 @@ tcp_server_start(void *aux)
val = 1;
setsockopt(tsl->fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
to.tv_sec = 30;
to.tv_usec = 0;
setsockopt(tsl->fd, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof(to));
tsl->start(tsl->fd, tsl->opaque, &tsl->peer, &tsl->self);
free(tsl);

View file

@ -161,6 +161,11 @@ http_stream_run(http_connection_t *hc, streaming_queue_t *sq,
else
name = "Live Stream";
/* reduce timeout on write() for streaming */
tp.tv_sec = 5;
tp.tv_usec = 0;
setsockopt(hc->hc_fd, SOL_SOCKET, SO_SNDTIMEO, &tp, sizeof(tp));
while(run) {
pthread_mutex_lock(&sq->sq_mutex);
sm = TAILQ_FIRST(&sq->sq_queue);