]> granicus.if.org Git - libevent/commitdiff
On connect, call only one of BEV_EVENT_CONNECTED or writecb.
authorNick Mathewson <nickm@torproject.org>
Wed, 19 Aug 2009 20:55:25 +0000 (20:55 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 19 Aug 2009 20:55:25 +0000 (20:55 +0000)
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

ChangeLog
bufferevent_sock.c

index ad9665c5ad40c382047003829db9ad0425daa3ec..cb4900af28fc82478195571b86ae4e85536b8a30 100644 (file)
--- 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:
index 3f32b1db121faa7f4d75e4792158d96a621070de..f78fc094ec0456fc5f8902d63e0e28f5fe23f9f6 100644 (file)
@@ -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);