]> granicus.if.org Git - libevent/commitdiff
bufferevent_socket_connect{,_hostname}() missing event callback and use ret code
authorJesse Fang <boycht@gmail.com>
Fri, 23 Feb 2018 11:15:12 +0000 (19:15 +0800)
committerAzat Khuzhin <a3at.mail@gmail.com>
Mon, 23 Apr 2018 23:05:30 +0000 (02:05 +0300)
- 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

index 38f791ee4ddbfa85e140e12f2d7438c92abc031c..8c78c045315cef0693cfa7ea36f1bb7031371bae 100644 (file)
@@ -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);
 }