diff --git a/main/http.c b/main/http.c index d6bc006f3e27324bb9b69604b415d0939285b76a..9d213ef612dca93ce9ae64ee38714e2d54631ef1 100644 --- a/main/http.c +++ b/main/http.c @@ -1240,11 +1240,27 @@ static void *httpd_helper_thread(void *data) enum ast_http_method http_method = AST_HTTP_UNKNOWN; const char *transfer_encoding; int remaining_headers; + struct protoent *p; if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) { goto done; } + /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm. + * This is necessary to prevent delays (caused by buffering) as we + * write to the socket in bits and pieces. */ + p = getprotobyname("tcp"); + if (p) { + int arg = 1; + if( setsockopt(ser->fd, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) { + ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno)); + ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n"); + } + } else { + ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection, getprotobyname(\"tcp\") failed\n"); + ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n"); + } + if (!fgets(buf, sizeof(buf), ser->f)) { goto done; } diff --git a/main/manager.c b/main/manager.c index 0180af8c32077fb660e6b99ffa8d61b552c2cb21..09ec032bdea473f1405afdca967b8f7487798006 100644 --- a/main/manager.c +++ b/main/manager.c @@ -5866,7 +5866,7 @@ static void *session_do(void *data) /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm. * This is necessary to prevent delays (caused by buffering) as we - * write to the socket in bits and peices. */ + * write to the socket in bits and pieces. */ p = getprotobyname("tcp"); if (p) { int arg = 1;