Fix some bugs in bufferevent_socket_connect

svn:r1398
This commit is contained in:
Nick Mathewson 2009-07-30 20:41:31 +00:00
parent 7a2a51a3a1
commit d1a2254bf2
2 changed files with 14 additions and 0 deletions

View File

@ -6,6 +6,8 @@ Changes in 2.0.3-alpha:
o Try to compile better with MSVC: patches from Brodie Thiesfield
o New evconnlistener_get_fd function to expose a listener's associated socket.
o Expose an ev_socklen_t type for consistent use across platforms.
o Make bufferevenr_socket_connect() work when the original fd was -1.
o Fix a bug in bufferevent_socket_connect() when the connection succeeds too quickly.
Changes in 2.0.2-alpha:
o Add a new flag to bufferevents to make all callbacks automatically deferred.

View File

@ -282,6 +282,7 @@ bufferevent_socket_connect(struct bufferevent *bev,
evutil_socket_t fd;
int r;
int result=-1;
int ownfd = 0;
_bufferevent_incref_and_lock(bev);
@ -289,9 +290,19 @@ bufferevent_socket_connect(struct bufferevent *bev,
goto done;
fd = bufferevent_getfd(bev);
if (fd < 0) {
fd = socket(sa->sa_family, SOCK_STREAM, 0);
if (fd < 0)
goto done;
if (evutil_make_socket_nonblocking(fd)<0)
goto done;
ownfd = 1;
}
r = evutil_socket_connect(&fd, sa, socklen);
if (r < 0) {
_bufferevent_run_eventcb(bev, BEV_EVENT_ERROR);
if (ownfd)
EVUTIL_CLOSESOCKET(fd);
/* do something about the error? */
goto done;
}
@ -305,6 +316,7 @@ bufferevent_socket_connect(struct bufferevent *bev,
}
} else {
/* The connect succeeded already. How odd. */
result = 0;
_bufferevent_run_eventcb(bev, BEV_EVENT_CONNECTED);
}