X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fio%2Fio.c;h=8e2695292bb158a15130c0754dbbee94ac2bfb71;hb=12e924346b342c61219a3fdc57eb6b00a27f1cd1;hp=4c73b62455693f6ae5c633c910921583cd3a5089;hpb=ab6e77749bfe678bde2cdf1442145bfbcaea253d;p=ccan diff --git a/ccan/io/io.c b/ccan/io/io.c index 4c73b624..8e269529 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -198,7 +198,7 @@ struct io_conn *io_duplex_(struct io_conn *old, struct io_plan plan) return conn; } -bool io_timeout_(struct io_conn *conn, struct timespec ts, +bool io_timeout_(struct io_conn *conn, struct timerel t, struct io_plan (*cb)(struct io_conn *, void *), void *arg) { assert(cb); @@ -212,7 +212,7 @@ bool io_timeout_(struct io_conn *conn, struct timespec ts, conn->timeout->next = cb; conn->timeout->next_arg = arg; - backend_add_timeout(conn, ts); + backend_add_timeout(conn, t); return true; } @@ -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) {