]> granicus.if.org Git - libevent/commitdiff
When bufferevent_socket_connect is called with no address, assume that our existing...
authorNick Mathewson <nickm@torproject.org>
Sun, 9 Aug 2009 20:17:29 +0000 (20:17 +0000)
committerNick Mathewson <nickm@torproject.org>
Sun, 9 Aug 2009 20:17:29 +0000 (20:17 +0000)
svn:r1411

bufferevent_sock.c
include/event2/bufferevent.h

index f1eb07778ffef62aa316ee098cff391341fe02e3..035add36fdee4251912d30ec05cedd701c56c18f 100644 (file)
@@ -280,7 +280,7 @@ bufferevent_socket_connect(struct bufferevent *bev,
            EVUTIL_UPCAST(bev, struct bufferevent_private, bev);
 
        evutil_socket_t fd;
-       int r;
+       int r = 0;
        int result=-1;
        int ownfd = 0;
 
@@ -291,6 +291,8 @@ bufferevent_socket_connect(struct bufferevent *bev,
 
        fd = bufferevent_getfd(bev);
        if (fd < 0) {
+               if (!sa)
+                       goto done;
                fd = socket(sa->sa_family, SOCK_STREAM, 0);
                if (fd < 0)
                        goto done;
@@ -298,15 +300,16 @@ bufferevent_socket_connect(struct bufferevent *bev,
                        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)) {
index cc3be0500e01494baa9eae25d09ace1af83a0c96..f8eae4024b9c3126918cb183cf83c793d2c82d93 100644 (file)
@@ -150,6 +150,10 @@ struct bufferevent *bufferevent_socket_new(struct event_base *base, evutil_socke
    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