]> git.ozlabs.org Git - ccan/blobdiff - ccan/io/io.c
ccan/io: fix io_connect.
[ccan] / ccan / io / io.c
index 3f618249d279d260d77c60aa8ac1c87645a0378b..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,
@@ -403,8 +406,8 @@ struct io_plan io_connect_(int fd, const struct addrinfo *addr,
        plan.next_arg = arg;
 
        /* Save old flags, set nonblock if not already. */
-       plan.u1.s = fcntl(fd, F_GETFD);
-       fcntl(fd, F_SETFD, plan.u1.s | O_NONBLOCK);
+       plan.u1.s = fcntl(fd, F_GETFL);
+       fcntl(fd, F_SETFL, plan.u1.s | O_NONBLOCK);
 
        /* Immediate connect can happen. */
        if (connect(fd, addr->ai_addr, addr->ai_addrlen) == 0) {