# HG changeset patch # User Adam Chlipala # Date 1388230028 18000 # Node ID 68c8ffc4ae699aee98a0161aac0f5969a7465890 # Parent 3ecd0b6360eb2a8558c56136e34223657806c55b Make HTTP keepalive switch between available connections to improve throughput diff -r 3ecd0b6360eb -r 68c8ffc4ae69 src/c/http.c --- 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;