]> git.ozlabs.org Git - ccan/commitdiff
ccan/io: fix io_connect.
authorRusty Russell <rusty@rustcorp.com.au>
Sun, 3 Aug 2014 00:25:01 +0000 (09:55 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Sun, 3 Aug 2014 00:25:01 +0000 (09:55 +0930)
getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &len) gives err == ECONNREFUSED
when connection is refused.  Handle this (and other error cases).

And we need F_SETFL not F_SETFD to restore blocking on the socket!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io/io.c

index bac08c9f9effd984c6297da04af9211d2e5c8ba3..8e2695292bb158a15130c0754dbbee94ac2bfb71 100644 (file)
@@ -385,10 +385,13 @@ static int do_connect(int fd, struct io_plan *plan)
 
        if (err == 0) {
                /* Restore blocking if it was initially. */
-               fcntl(fd, F_SETFD, plan->u1.s);
+               fcntl(fd, F_SETFL, plan->u1.s);
                return 1;
-       }
-       return 0;
+       } else if (err == EINPROGRESS)
+               return 0;
+
+       errno = err;
+       return -1;
 }
 
 struct io_plan io_connect_(int fd, const struct addrinfo *addr,