summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog1
-rw-r--r--bufferevent_sock.c4
2 files changed, 4 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index ad9665c5..cb4900af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@ Changes in 2.0.3-alpha:
o Have bufferevent_socket_connect() with no arguments put a bufferevent into connecting mode.
o Support sendfile on Solaris: patch from Caitlin Mercer.
o New functions to explicitly reference a socket used by an evhttp object. Patches from David Reiss.
+ o When we send a BEV_EVENT_CONNECTED to indicate connected status, we no longer invoke the write callback as well unless we actually wrote data too.
Changes in 2.0.2-alpha:
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);