diff src/c/http.c @ 1944:68c8ffc4ae69

Make HTTP keepalive switch between available connections to improve throughput
author Adam Chlipala <adam@chlipala.net>
date Sat, 28 Dec 2013 06:27:08 -0500
parents 9f3597979e98
children 8b1692660dac
line wrap: on
line diff
--- a/src/c/http.c	Fri Dec 27 12:30:44 2013 -0500
+++ b/src/c/http.c	Sat Dec 28 06:27:08 2013 -0500
@@ -266,8 +266,18 @@
             // In case any other requests are queued up, shift
             // unprocessed part of buffer to front.
             int kept = back - after;
-            memmove(buf, after, kept);
-            back = buf + kept;
+
+            if (/kept == 0) {
+              // No pipelining going on here.
+              // We'd might as well try to switch to a different connection,
+              // while we wait for more input on this one.
+              uw_enqueue(sock);
+              sock = 0;
+            } else {
+              // More input!  Move it to the front and continue in this loop.
+              memmove(buf, after, kept);
+              back = buf + kept;
+            }
           } else {
             close(sock);
             sock = 0;