EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
evutil_socket_t fd;
- int r;
+ int r = 0;
int result=-1;
int ownfd = 0;
fd = bufferevent_getfd(bev);
if (fd < 0) {
+ if (!sa)
+ goto done;
fd = socket(sa->sa_family, SOCK_STREAM, 0);
if (fd < 0)
goto done;
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;
+ if (sa) {
+ 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;
+ }
}
-
bufferevent_setfd(bev, fd);
if (r == 0) {
if (! bufferevent_enable(bev, EV_WRITE)) {
If the bufferevent does not already have a socket set, we allocate a new
socket here and make it nonblocking before we begin.
+ If no address is provided, we assume that the socket is already connecting,
+ and configure the bufferevent so that a BEV_EVENT_CONNECTED event will be
+ yielded when it is done connecting.
+
@param bufev an existing bufferevent allocated with
bufferevent_socket_new().
@param addr the address we should connect to