From 12e924346b342c61219a3fdc57eb6b00a27f1cd1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 3 Aug 2014 09:55:01 +0930 Subject: [PATCH] ccan/io: fix io_connect. 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 --- ccan/io/io.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ccan/io/io.c b/ccan/io/io.c index bac08c9f..8e269529 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -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, -- 2.39.2