From: reyk Date: Wed, 6 Aug 2014 11:24:12 +0000 (+0000) Subject: The watermark exposed a bug in server_write that broke keep-alive X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2cadac13c6ac84d7c92ff89932756918c24116e4;p=openbsd The watermark exposed a bug in server_write that broke keep-alive support. Instead of calling server_close from server_write, we have to proceed to the next connection by calling the error handler. OK jsg@ --- diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index 6460f357237..77168e95ca3 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -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 @@ -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)); diff --git a/usr.sbin/httpd/server_file.c b/usr.sbin/httpd/server_file.c index 5b72aaf4683..65ecb0100b8 100644 --- a/usr.sbin/httpd/server_file.c +++ b/usr.sbin/httpd/server_file.c @@ -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 @@ -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; }