From f7bc1337977553f5f966f13840a5f7feba2d0bd5 Mon Sep 17 00:00:00 2001 From: Jesse Fang Date: Fri, 23 Feb 2018 19:15:12 +0800 Subject: [PATCH] bufferevent_socket_connect{,_hostname}() missing event callback and use ret code - 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. - Make bufferevent_socket_connect()'s behavior more consistent: function return error then no callback, function return ok then error passed by event callback. Fixes: #597 Closes: #599 Closes: #600 --- bufferevent_sock.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bufferevent_sock.c b/bufferevent_sock.c index 38f791ee..8c78c045 100644 --- a/bufferevent_sock.c +++ b/bufferevent_sock.c @@ -396,7 +396,7 @@ bufferevent_socket_connect(struct bufferevent *bev, fd = evutil_socket_(sa->sa_family, SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0); if (fd < 0) - goto done; + goto freesock; ownfd = 1; } if (sa) { @@ -446,10 +446,8 @@ bufferevent_socket_connect(struct bufferevent *bev, goto done; freesock: - bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); if (ownfd) evutil_closesocket(fd); - /* do something about the error? */ done: bufferevent_decref_and_unlock_(bev); return result; @@ -485,10 +483,10 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai, } /* XXX use the other addrinfos? */ - /* XXX use this return value */ bufferevent_socket_set_conn_address(bev_p, ai->ai_addr, (int)ai->ai_addrlen); r = bufferevent_socket_connect(bev, ai->ai_addr, (int)ai->ai_addrlen); - (void)r; + if (r < 0) + bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0); bufferevent_decref_and_unlock_(bev); evutil_freeaddrinfo(ai); } -- 2.40.0