http: fix detecting EOF without write

Before this patch http server don't knows when client disconnected until it
will try to write to it, IOW to detect is client still alive you need to write
something to client socket, however it is not convenient since it requires to
store all clients somewhere and poll them periodically, and I don't see any
regressions if we will leave EV_READ always (like libevhtp do), since we
already reset read callback in evhttp_write_buffer() (see
http/write_during_read).

Also since we don't disable EV_READ anymore we don't need some enable EV_READ,
so we will reduce number of epoll_ctl() calls.

Covered-by: http/terminate_chunked_oneshot
Covered-by: http/write_during_read
Fixes: #78
This commit is contained in:
Azat Khuzhin 2015-09-08 16:40:55 +03:00
parent 3d15aeb4fd
commit 7ed02ac129

11
http.c
View File

@ -969,7 +969,6 @@ evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req)
case MORE_DATA_EXPECTED:
case REQUEST_CANCELED: /* ??? */
default:
bufferevent_enable(evcon->bufev, EV_READ);
break;
}
}
@ -1051,9 +1050,6 @@ evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req)
evhttp_connection_done(evcon);
return;
}
/* Read more! */
bufferevent_enable(evcon->bufev, EV_READ);
}
#define get_deferred_queue(evcon) \
@ -2180,9 +2176,6 @@ evhttp_read_header(struct evhttp_connection *evcon,
return;
}
/* Disable reading for now */
bufferevent_disable(evcon->bufev, EV_READ);
/* Callback can shut down connection with negative return value */
if (req->header_cb != NULL) {
if ((*req->header_cb)(req, req->cb_arg) < 0) {
@ -2595,9 +2588,9 @@ evhttp_cancel_request(struct evhttp_request *req)
void
evhttp_start_read_(struct evhttp_connection *evcon)
{
/* Set up an event to read the headers */
bufferevent_disable(evcon->bufev, EV_WRITE);
bufferevent_enable(evcon->bufev, EV_READ);
evcon->state = EVCON_READING_FIRSTLINE;
/* Reset the bufferevent callbacks */
bufferevent_setcb(evcon->bufev,
@ -4062,6 +4055,8 @@ evhttp_get_request_connection(
evcon->fd = fd;
bufferevent_enable(evcon->bufev, EV_READ);
bufferevent_disable(evcon->bufev, EV_WRITE);
bufferevent_setfd(evcon->bufev, fd);
return (evcon);