summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2013-12-12 15:25:46 +1030
committerRusty Russell <rusty@rustcorp.com.au>2013-12-12 15:25:46 +1030
commitfc8acdbbe2484794aa3c3bea8c00f0de80e48811 (patch)
tree54dd1e01d34892c3adbe38827913434b7a7985bd
parent12ab811533406e22b78ce8b227474f1056375ae4 (diff)
net: fix async connect to non-listening port.
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>
-rw-r--r--ccan/net/net.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ccan/net/net.c b/ccan/net/net.c
index d2eaa9ec..394c4e49 100644
--- a/ccan/net/net.c
+++ b/ccan/net/net.c
@@ -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);