]> granicus.if.org Git - libevent/commitdiff
be_sock: handle readv() returns ECONNREFUSED (freebsd 9.2)
authorAzat Khuzhin <a3at.mail@gmail.com>
Wed, 10 Aug 2016 13:04:33 +0000 (16:04 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Wed, 10 Aug 2016 21:11:05 +0000 (00:11 +0300)
During testing sometimes bufferevent/bufferevent_connect_fail_eventcb fails,
and after some digging I found that this was the case when connect() doesn't
return ECONNREFUSED immediately, and instead next operation will return it (in
our case evbuffer_read()->readv(), needless to say that after this
bufferevent_writecb() called and it checks error with getsockopt() but of
course it doesn't return any error), so this patch checks "errno" after
"readv()" and installs "bufev::connection_refused" flag, to handle this from
writecb and only once.

Fixes: bufferevent/bufferevent_connect_fail_eventcb
Fixes: bufferevent/bufferevent_connect_fail_eventcb_defer
Refs: #388

bufferevent_sock.c

index ab35f8799c66096d36981cfa2392dd2876ca2f49..58095f37de770c499edcf17e1e1e37633c085d3b 100644 (file)
@@ -192,6 +192,10 @@ bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
                int err = evutil_socket_geterror(fd);
                if (EVUTIL_ERR_RW_RETRIABLE(err))
                        goto reschedule;
+               if (EVUTIL_ERR_CONNECT_REFUSED(err)) {
+                       bufev_p->connection_refused = 1;
+                       goto done;
+               }
                /* error case */
                what |= BEV_EVENT_ERROR;
        } else if (res == 0) {