The watermark exposed a bug in server_write that broke keep-alive
authorreyk <reyk@openbsd.org>
Wed, 6 Aug 2014 11:24:12 +0000 (11:24 +0000)
committerreyk <reyk@openbsd.org>
Wed, 6 Aug 2014 11:24:12 +0000 (11:24 +0000)
support.  Instead of calling server_close from server_write, we have
to proceed to the next connection by calling the error handler.

OK jsg@

usr.sbin/httpd/server.c
usr.sbin/httpd/server_file.c

index 6460f35..77168e9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server.c,v 1.33 2014/08/06 09:40:04 reyk Exp $        */
+/*     $OpenBSD: server.c,v 1.34 2014/08/06 11:24:12 reyk Exp $        */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -688,9 +688,11 @@ server_write(struct bufferevent *bev, void *arg)
 
        if (clt->clt_done)
                goto done;
+
+       bufferevent_enable(bev, EV_READ);
        return;
  done:
-       server_close(clt, "last write (done)");
+       (*bev->errorcb)(bev, EVBUFFER_WRITE|EVBUFFER_EOF, bev->cbarg);
        return;
 }
 
@@ -728,10 +730,9 @@ server_read(struct bufferevent *bev, void *arg)
                goto fail;
        if (clt->clt_done)
                goto done;
-       bufferevent_enable(bev, EV_READ);
        return;
  done:
-       server_close(clt, "last read (done)");
+       (*bev->errorcb)(bev, EVBUFFER_READ|EVBUFFER_EOF, bev->cbarg);
        return;
  fail:
        server_close(clt, strerror(errno));
index 5b72aaf..65ecb01 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: server_file.c,v 1.30 2014/08/06 09:36:31 reyk Exp $   */
+/*     $OpenBSD: server_file.c,v 1.31 2014/08/06 11:24:12 reyk Exp $   */
 
 /*
  * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
@@ -375,13 +375,6 @@ server_file_error(struct bufferevent *bev, short error, void *arg)
 
                clt->clt_done = 1;
 
-               dst = EVBUFFER_OUTPUT(clt->clt_bev);
-               if (EVBUFFER_LENGTH(dst)) {
-                       /* Finish writing all data first */
-                       bufferevent_enable(clt->clt_bev, EV_WRITE);
-                       return;
-               }
-
                if (clt->clt_persist) {
                        /* Close input file and wait for next HTTP request */
                        if (clt->clt_fd != -1)
@@ -392,6 +385,14 @@ server_file_error(struct bufferevent *bev, short error, void *arg)
                        bufferevent_enable(clt->clt_bev, EV_READ|EV_WRITE);
                        return;
                }
+
+               dst = EVBUFFER_OUTPUT(clt->clt_bev);
+               if (EVBUFFER_LENGTH(dst)) {
+                       /* Finish writing all data first */
+                       bufferevent_enable(clt->clt_bev, EV_WRITE);
+                       return;
+               }
+
                server_close(clt, "done");
                return;
        }