Skip to content

Commit

Permalink
bufferevent_socket_connect{,_hostname}() missing event callback and u…
Browse files Browse the repository at this point in the history
…se 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: libevent#597
Closes: libevent#599
Closes: libevent#600
  • Loading branch information
boytm authored and azat committed Apr 23, 2018
1 parent 623ef3c commit f7bc133
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bufferevent_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit f7bc133

Please sign in to comment.