diff --git a/bufferevent_sock.c b/bufferevent_sock.c index 58095f37..93aedb33 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -249,8 +249,8 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg) /* we need to fake the error if the connection was refused * immediately - usually connection to localhost on BSD */ if (bufev_p->connection_refused) { - bufev_p->connection_refused = 0; - c = -1; + bufev_p->connection_refused = 0; + c = -1; } if (c == 0) @@ -438,13 +438,12 @@ bufferevent_socket_connect(struct bufferevent *bev, /* The connect succeeded already. How very BSD of it. */ result = 0; bufev_p->connecting = 1; - event_active(&bev->ev_write, EV_WRITE, 1); + bufferevent_trigger_nolock_(bev, EV_WRITE, BEV_OPT_DEFER_CALLBACKS); } else { /* The connect failed already. How very BSD of it. */ - bufev_p->connection_refused = 1; - bufev_p->connecting = 1; result = 0; - event_active(&bev->ev_write, EV_WRITE, 1); + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, BEV_OPT_DEFER_CALLBACKS); + bufferevent_disable(bev, EV_WRITE|EV_READ); } goto done;