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
This commit is contained in:
Jesse Fang 2018-02-23 19:15:12 +08:00 committed by Azat Khuzhin
parent 623ef3ccdc
commit f7bc133797

View File

@ -396,7 +396,7 @@ bufferevent_socket_connect(struct bufferevent *bev,
fd = evutil_socket_(sa->sa_family, fd = evutil_socket_(sa->sa_family,
SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0); SOCK_STREAM|EVUTIL_SOCK_NONBLOCK, 0);
if (fd < 0) if (fd < 0)
goto done; goto freesock;
ownfd = 1; ownfd = 1;
} }
if (sa) { if (sa) {
@ -446,10 +446,8 @@ bufferevent_socket_connect(struct bufferevent *bev,
goto done; goto done;
freesock: freesock:
bufferevent_run_eventcb_(bev, BEV_EVENT_ERROR, 0);
if (ownfd) if (ownfd)
evutil_closesocket(fd); evutil_closesocket(fd);
/* do something about the error? */
done: done:
bufferevent_decref_and_unlock_(bev); bufferevent_decref_and_unlock_(bev);
return result; return result;
@ -485,10 +483,10 @@ bufferevent_connect_getaddrinfo_cb(int result, struct evutil_addrinfo *ai,
} }
/* XXX use the other addrinfos? */ /* XXX use the other addrinfos? */
/* XXX use this return value */
bufferevent_socket_set_conn_address(bev_p, ai->ai_addr, (int)ai->ai_addrlen); 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); 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); bufferevent_decref_and_unlock_(bev);
evutil_freeaddrinfo(ai); evutil_freeaddrinfo(ai);
} }