mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
bufferevent_socket_connect{,_hostname}() missing event callback and use ret code
[ Upstream commit f7bc1337977553f5f966f13840a5f7feba2d0bd5 ] - When socket() failed in bufferevent_socket_connect() , the event callback should be called also in bufferevent_socket_connect_hostname(). eg. when use bufferevent_socket_connect_hostname() to resolve and connect an IP address but process have a smaller ulimit open files, socket() fails always but caller is not notified. - When make socket nonblocking failed in bufferevent_socket_connect(), free the fd. - Make bufferevent_socket_connect()'s behavior more consistent: function return error then no callback, function return ok then error passed by event callback. Backport-for: 2.0 Refs: #597 Refs: #599 Refs: #600 Closes: #599 (cherry-pick)
This commit is contained in:
parent
d148783103
commit
d22efeb134
@ -373,9 +373,9 @@ bufferevent_socket_connect(struct bufferevent *bev,
|
||||
fd = socket(sa->sa_family, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
goto done;
|
||||
if (evutil_make_socket_nonblocking(fd)<0)
|
||||
goto done;
|
||||
ownfd = 1;
|
||||
if (evutil_make_socket_nonblocking(fd)<0)
|
||||
goto freesock;
|
||||
}
|
||||
if (sa) {
|
||||
#ifdef WIN32
|
||||
@ -425,7 +425,6 @@ bufferevent_socket_connect(struct bufferevent *bev,
|
||||
goto done;
|
||||
|
||||
freesock:
|
||||
_bufferevent_run_eventcb(bev, BEV_EVENT_ERROR);
|
||||
if (ownfd)
|
||||
evutil_closesocket(fd);
|
||||
/* do something about the error? */
|
||||
@ -457,9 +456,9 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
|
||||
}
|
||||
|
||||
/* XXX use the other addrinfos? */
|
||||
/* XXX use this return value */
|
||||
r = bufferevent_socket_connect(bev, ai->ai_addr, (int)ai->ai_addrlen);
|
||||
(void)r;
|
||||
if (r < 0)
|
||||
_bufferevent_run_eventcb(bev, BEV_EVENT_ERROR);
|
||||
_bufferevent_decref_and_unlock(bev);
|
||||
evutil_freeaddrinfo(ai);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user