]> granicus.if.org Git - libevent/commitdiff
http: try to read existing data in buffer under EVHTTP_CON_READ_ON_WRITE_ERROR
authorAzat Khuzhin <azat@libevent.org>
Mon, 28 Jan 2019 22:09:44 +0000 (01:09 +0300)
committerAzat Khuzhin <azat@libevent.org>
Mon, 28 Jan 2019 22:16:48 +0000 (01:16 +0300)
There are two possible ways of getting response from the server:
- processing existing bufferevent buffer
- reading from the socket (even after write() errored with -1, it is
still possible)

But we did not tried the first option, only the second one.

Fixes: http/read_on_write_error (on freebsd/osx)
http.c

diff --git a/http.c b/http.c
index 4e114b70a47794911ea7b60b9d9f394f70f2b526..3b48a7382e5fb0aa2af03ea04f5b30e9cd1558b4 100644 (file)
--- a/http.c
+++ b/http.c
@@ -1534,6 +1534,14 @@ evhttp_error_cb(struct bufferevent *bufev, short what, void *arg)
                        return;
                }
 
+               if (what & BEV_EVENT_READING &&
+                       evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR &&
+                       evbuffer_get_length(bufferevent_get_input(bufev))) {
+                       event_deferred_cb_schedule_(get_deferred_queue(evcon),
+                           &evcon->read_more_deferred_cb);
+                       return;
+               }
+
                evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF);
        } else if (what == BEV_EVENT_CONNECTED) {
        } else {