]> git.ozlabs.org Git - ccan/commitdiff
net: fix async connect to non-listening port.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 12 Dec 2013 04:55:46 +0000 (15:25 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 12 Dec 2013 04:55:46 +0000 (15:25 +1030)
In this case, Linux (at least, Ubuntu 13.10, x86-64 kernel 3.11.0-14-generic)
sets POLLHUP and gives no other error notification.

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

index d2eaa9ecb45e58660fb80ea607210226d3385a7f..394c4e49f2bb16024ea576b0aa68ed1376c25bcc 100644 (file)
@@ -148,6 +148,17 @@ int net_connect_complete(struct pollfd pfds[2])
 
                if (pfds[i].fd == -1)
                        continue;
+               if (pfds[i].revents & POLLHUP) {
+                       /* Linux gives this if connecting to local
+                        * non-listening port */
+                       close(pfds[i].fd);
+                       pfds[i].fd = -1;
+                       if (pfds[!i].fd == -1) {
+                               errno = ECONNREFUSED;
+                               return -1;
+                       }
+                       continue;
+               }
                if (getsockopt(pfds[i].fd, SOL_SOCKET, SO_ERROR, &err,
                               &errlen) != 0) {
                        net_connect_abort(pfds);