From: Nick Mathewson Date: Thu, 24 Dec 2009 22:47:14 +0000 (-0500) Subject: Do not make bufferevent_setfd implicitly disable EV_READ and EV_WRITE. X-Git-Tag: release-2.0.4-alpha~93^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82743794d37b0ddece31c0d4f637d2f7d0896f2d;p=libevent Do not make bufferevent_setfd implicitly disable EV_READ and EV_WRITE. This obviates the need for BEV_SUSPEND_CONNECTING, and good riddance. --- diff --git a/bufferevent-internal.h b/bufferevent-internal.h index 220cdeb7..9594784a 100644 --- a/bufferevent-internal.h +++ b/bufferevent-internal.h @@ -53,9 +53,6 @@ extern "C" { #define BEV_SUSPEND_BW 0x02 /* On a base bufferevent: when we have emptied the group's bandwidth bucket. */ #define BEV_SUSPEND_BW_GROUP 0x04 -/* On a socket bufferevent: we aren't going to try reading until the - * connect operation is done. */ -#define BEV_SUSPEND_CONNECTING 0x08 struct bufferevent_rate_limit_group { /** List of all members in the group */ diff --git a/bufferevent_openssl.c b/bufferevent_openssl.c index e2cb28b1..3ec56f74 100644 --- a/bufferevent_openssl.c +++ b/bufferevent_openssl.c @@ -678,6 +678,7 @@ consider_reading(struct bufferevent_openssl *bev_ssl) if (bev_ssl->write_blocked_on_read) return; while ((bev_ssl->bev.bev.enabled & EV_READ) && + (! bev_ssl->bev.read_suspended) && (! wm->high || evbuffer_get_length(input) < wm->high)) { int n_to_read = wm->high ? wm->high - evbuffer_get_length(input) @@ -708,6 +709,7 @@ consider_writing(struct bufferevent_openssl *bev_ssl) wm = &bev_ssl->underlying->wm_write; } while ((bev_ssl->bev.bev.enabled & EV_WRITE) && + (! bev_ssl->bev.write_suspended) && evbuffer_get_length(output) && (!target || (! wm->high || evbuffer_get_length(target) < wm->high))) { int n_to_write; diff --git a/bufferevent_sock.c b/bufferevent_sock.c index f53689ee..d1b5792a 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -222,7 +222,6 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) goto done; } else { connected = 1; - bufferevent_unsuspend_read(bufev, BEV_SUSPEND_CONNECTING); #ifdef WIN32 if (BEV_IS_ASYNC(bufev)) { event_del(&bufev->ev_write); @@ -408,11 +407,7 @@ freesock: if (ownfd) EVUTIL_CLOSESOCKET(fd); /* do something about the error? */ - done: - if (result == 0) - bufferevent_suspend_read(bev, BEV_SUSPEND_CONNECTING); - _bufferevent_decref_and_unlock(bev); return result; } @@ -575,6 +570,10 @@ be_socket_setfd(struct bufferevent *bufev, evutil_socket_t fd) EV_READ|EV_PERSIST, bufferevent_readcb, bufev); event_assign(&bufev->ev_write, bufev->ev_base, fd, EV_WRITE|EV_PERSIST, bufferevent_writecb, bufev); + + if (fd >= 0) + bufferevent_enable(bufev, bufev->enabled); + BEV_UNLOCK(bufev); }