From d4054928c738c35cae38b8c6b23bc26816ee1833 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 11 Mar 2016 20:17:51 +0300 Subject: [PATCH] http: make fallback for EVHTTP_CON_READ_ON_WRITE_ERROR more cleaner --- http.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/http.c b/http.c index cdadf483..cce68ce6 100644 --- a/http.c +++ b/http.c @@ -1348,6 +1348,8 @@ evhttp_connection_reset_(struct evhttp_connection *evcon) err = evbuffer_drain(tmp, -1); EVUTIL_ASSERT(!err && "drain input"); + evcon->flags &= ~EVHTTP_CON_READING_ERROR; + evcon->state = EVCON_DISCONNECTED; } @@ -1435,7 +1437,13 @@ evhttp_connection_read_on_write_error(struct evhttp_connection *evcon, { struct evbuffer *buf; - evcon->state = EVCON_READING_FIRSTLINE; + /** Second time, we can't read anything */ + if (evcon->flags & EVHTTP_CON_READING_ERROR) { + evcon->flags &= ~EVHTTP_CON_READING_ERROR; + evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); + return; + } + req->kind = EVHTTP_RESPONSE; buf = bufferevent_get_output(evcon->bufev); @@ -1443,12 +1451,7 @@ evhttp_connection_read_on_write_error(struct evhttp_connection *evcon, evbuffer_drain(buf, evbuffer_get_length(buf)); evbuffer_freeze(buf, 1); - bufferevent_setcb(evcon->bufev, - evhttp_read_cb, - NULL, /* evhttp_write_cb */ - evhttp_error_cb, - evcon); - evhttp_connection_start_detectclose(evcon); + evhttp_start_read_(evcon); evcon->flags |= EVHTTP_CON_READING_ERROR; } @@ -1497,12 +1500,6 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg) */ if (evcon->flags & EVHTTP_CON_CLOSEDETECT) { evcon->flags &= ~EVHTTP_CON_CLOSEDETECT; - if (evcon->flags & EVHTTP_CON_READING_ERROR) { - evcon->flags &= ~EVHTTP_CON_READING_ERROR; - evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); - return; - } - EVUTIL_ASSERT(evcon->http_server == NULL); /* For connections from the client, we just * reset the connection so that it becomes -- 2.40.0