]> git.ozlabs.org Git - ccan/blobdiff - ccan/net/net.c
ccan: Correct some poor conventions in _info includes
[ccan] / ccan / net / net.c
index d2eaa9ecb45e58660fb80ea607210226d3385a7f..7867054d9adf6c39bb48d68d8221c09c19925b86 100644 (file)
@@ -116,7 +116,7 @@ int net_connect_async(const struct addrinfo *addrinfo, struct pollfd pfds[2])
                                close_noerr(pfds[i].fd);
                                return -1;
                        }
-                       return pfds[0].fd;
+                       return pfds[i].fd;
                }
        }
 
@@ -148,6 +148,20 @@ 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 (!(pfds[i].revents & POLLOUT))
+                       continue;
+
                if (getsockopt(pfds[i].fd, SOL_SOCKET, SO_ERROR, &err,
                               &errlen) != 0) {
                        net_connect_abort(pfds);