diff src/c/driver.c @ 682:5bbb542243e8

Redo channels, making them single-client
author Adam Chlipala <adamc@hcoop.net>
date Sun, 29 Mar 2009 11:37:29 -0400
parents 729e65db2e2f
children 9a2c18dab11d
line wrap: on
line diff
--- a/src/c/driver.c	Sat Mar 28 11:15:42 2009 -0400
+++ b/src/c/driver.c	Sun Mar 29 11:37:29 2009 -0400
@@ -171,10 +171,10 @@
           char *pass = uw_Basis_requestHeader(ctx, "UrWeb-Pass");
 
           if (id && pass) {
-            size_t idn = atoi(id);
+            unsigned idn = atoi(id);
             uw_client_connect(idn, atoi(pass), sock);
             dont_close = 1;
-            fprintf(stderr, "Processed request for messages by client %d\n\n", (int)idn);
+            fprintf(stderr, "Processed request for messages by client %u\n\n", idn);
           }
           break;
         }
@@ -217,6 +217,8 @@
             else {
               printf("Fatal error (out of retries): %s\n", uw_error_message(ctx));
 
+              try_rollback(ctx);
+
               uw_reset_keep_error_message(ctx);
               uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
               uw_write_header(ctx, "Content-type: text/plain\r\n");
@@ -224,8 +226,6 @@
               uw_write(ctx, uw_error_message(ctx));
               uw_write(ctx, "\n");
 
-              try_rollback(ctx);
-
               break;
             }
           } else if (fk == UNLIMITED_RETRY)
@@ -233,6 +233,8 @@
           else if (fk == FATAL) {
             printf("Fatal error: %s\n", uw_error_message(ctx));
 
+            try_rollback(ctx);
+
             uw_reset_keep_error_message(ctx);
             uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\r\n");
             uw_write_header(ctx, "Content-type: text/html\r\n");
@@ -241,26 +243,24 @@
             uw_write(ctx, uw_error_message(ctx));
             uw_write(ctx, "\n</body></html>");
 
-            try_rollback(ctx);
-
             break;
           } else {
             printf("Unknown uw_handle return code!\n");
 
+            try_rollback(ctx);
+
             uw_reset_keep_request(ctx);
             uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\n\r");
             uw_write_header(ctx, "Content-type: text/plain\r\n");
             uw_write(ctx, "Unknown uw_handle return code!\n");
 
-            try_rollback(ctx);
-
             break;
           }
 
-          uw_reset_keep_request(ctx);
-
           if (try_rollback(ctx))
             break;
+
+          uw_reset_keep_request(ctx);
         }
 
         uw_send(ctx, sock);