]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
HTTP: Add TCP_NODELAY to accepted connections
authorKinsey Moore <kmoore@digium.com>
Mon, 21 Apr 2014 16:15:34 +0000 (16:15 +0000)
committerKinsey Moore <kmoore@digium.com>
Mon, 21 Apr 2014 16:15:34 +0000 (16:15 +0000)
This adds the TCP_NODELAY option to accepted connections on the HTTP
server built into Asterisk. This option disables the Nagle algorithm
which controls queueing of outbound data and in some cases can cause
delays on receipt of response by the client due to how the Nagle
algorithm interacts with TCP delayed ACK. This option is already set on
all non-HTTP AMI connections and this change would cover standard HTTP
requests, manager HTTP connections, and ARI HTTP requests and
websockets in Asterisk 12+ along with any future use of the HTTP
server.

Review: https://reviewboard.asterisk.org/r/3466/
........

Merged revisions 412745 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 412748 from http://svn.asterisk.org/svn/asterisk/branches/11

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@412749 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/http.c
main/manager.c

index d6bc006f3e27324bb9b69604b415d0939285b76a..9d213ef612dca93ce9ae64ee38714e2d54631ef1 100644 (file)
@@ -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;
        }
index 6a315f126880b4d1ac1798abe4fdd9f7cfe33b71..7c285316c68f39023bf86e4bf34807b2f4df8fd2 100644 (file)
@@ -5864,7 +5864,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;