summaryrefslogtreecommitdiff
path: root/bufferevent_sock.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-08-19 20:55:25 +0000
committerNick Mathewson <nickm@torproject.org>2009-08-19 20:55:25 +0000
commitf65b8b0964bfd2653b5c6c9fbf1196310b77e084 (patch)
tree907f7ea2e2b6961228103b593f0a0c1b7f219666 /bufferevent_sock.c
parent2c1b0e442826baec932e614e8c730fd13ab3cd07 (diff)
downloadlibevent-f65b8b0964bfd2653b5c6c9fbf1196310b77e084.tar.gz
On connect, call only one of BEV_EVENT_CONNECTED or writecb.
Previously, if we had a socket bufferevent in connect state, we'd send both of these to indicate that the connection was done. That was broken since the point of adding BEV_EVENT_CONNECTED was so that we could distinguish "we're connected" and "we wrote something". Now, writecb is called only when A) the connection finished but the user never put the socket into a "connecting" state, or B) data was actually written. svn:r1425
Diffstat (limited to 'bufferevent_sock.c')
-rw-r--r--bufferevent_sock.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/bufferevent_sock.c b/bufferevent_sock.c
index 3f32b1db..f78fc094 100644
--- a/bufferevent_sock.c
+++ b/bufferevent_sock.c
@@ -183,6 +183,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
int res = 0;
short what = BEV_EVENT_WRITING;
+ int connected = 0;
_bufferevent_incref_and_lock(bufev);
@@ -192,6 +193,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
}
if (bufev_p->connecting) {
bufev_p->connecting = 0;
+ connected = 1;
_bufferevent_run_eventcb(bufev, BEV_EVENT_CONNECTED);
if (!(bufev->enabled & EV_WRITE)) {
event_del(&bufev->ev_write);
@@ -226,7 +228,7 @@ bufferevent_writecb(evutil_socket_t fd, short event, void *arg)
* Invoke the user callback if our buffer is drained or below the
* low watermark.
*/
- if (bufev->writecb != NULL &&
+ if (bufev->writecb != NULL && (res || !connected) &&
evbuffer_get_length(bufev->output) <= bufev->wm_write.low)
_bufferevent_run_writecb(bufev);