]> granicus.if.org Git - libevent/commitdiff
http: make fallback for EVHTTP_CON_READ_ON_WRITE_ERROR more cleaner
authorAzat Khuzhin <a3at.mail@gmail.com>
Fri, 11 Mar 2016 17:17:51 +0000 (20:17 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Fri, 11 Mar 2016 17:59:58 +0000 (20:59 +0300)
http.c

diff --git a/http.c b/http.c
index cdadf48308791337422743a9adf3cbe5f4613e2b..cce68ce63e05c3b59fd0d77ddbe588a15810df19 100644 (file)
--- 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