changeset 1937:94f9570671f0

Fix compilation of apps that don't use database; fix HTTP pipelining
author Adam Chlipala <adam@chlipala.net>
date Tue, 17 Dec 2013 20:12:33 -0500
parents 6745eafff617
children d02c1a0d8082
files src/c/http.c src/cjr_print.sml
diffstat 2 files changed, 30 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/http.c	Thu Dec 12 17:42:48 2013 -0500
+++ b/src/c/http.c	Tue Dec 17 20:12:33 2013 -0500
@@ -73,7 +73,7 @@
 static void *worker(void *data) {
   int me = *(int *)data;
   uw_context ctx = uw_request_new_context(me, &uw_application, NULL, log_error, log_debug);
-  size_t buf_size = 2;
+  size_t buf_size = 1024;
   char *buf = malloc(buf_size), *back = buf;
   uw_request_context rc = uw_new_request_context();
   int sock = 0;
@@ -99,28 +99,32 @@
         buf = new_buf;
       }
 
-      r = recv(sock, back, buf_size - 1 - (back - buf), 0);
+      *back = 0;
+      body = strstr(buf, "\r\n\r\n");
+      if (body == NULL) {
+        r = recv(sock, back, buf_size - 1 - (back - buf), 0);
 
-      if (r < 0) {
-        if (!quiet)
-          fprintf(stderr, "Recv failed\n");
-        close(sock);
-        sock = 0;
-        break;
+        if (r < 0) {
+          if (!quiet)
+            fprintf(stderr, "Recv failed\n");
+          close(sock);
+          sock = 0;
+          break;
+        }
+
+        if (r == 0) {
+          if (!quiet)
+            printf("Connection closed.\n");
+          close(sock);
+          sock = 0;
+          break;
+        }
+
+        back += r;
+        *back = 0;
       }
 
-      if (r == 0) {
-        if (!quiet)
-          printf("Connection closed.\n");
-        close(sock);
-        sock = 0;
-        break;
-      }
-
-      back += r;
-      *back = 0;
-
-      if ((body = strstr(buf, "\r\n\r\n"))) {
+      if (body != NULL || (body = strstr(buf, "\r\n\r\n"))) {
         request_result rr;
         int should_keepalive = 0;
 
@@ -213,6 +217,11 @@
 
         s = headers;
         while ((s2 = strchr(s, '\r'))) {
+          if (s2 == s) {
+            *s = 0;
+            break;
+          }
+
           s = s2;
 
           if (s[1] == 0)
--- a/src/cjr_print.sml	Thu Dec 12 17:42:48 2013 -0500
+++ b/src/cjr_print.sml	Tue Dec 17 20:12:33 2013 -0500
@@ -3364,7 +3364,7 @@
                       newline,
                       string "static void uw_db_init(uw_context ctx) { };",
                       newline,
-                      string "static int uw_db_begin(uw_context ctx) { return 0; };",
+                      string "static int uw_db_begin(uw_context ctx, int could_write) { return 0; };",
                       newline,
                       string "static void uw_db_close(uw_context ctx) { };",
                       newline,