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
This commit is contained in:
Nick Mathewson 2009-08-19 20:55:25 +00:00
parent 2c1b0e4428
commit f65b8b0964
2 changed files with 4 additions and 1 deletions

View File

@ -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:

View 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);