net: don't return still-connecting fd.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 27 May 2014 03:47:29 +0000 (13:17 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 27 May 2014 03:47:29 +0000 (13:17 +0930)
If one connect failed, we'd return the other one without
waiting for the connect to complete.  This resulted in
read() returning 0, which was really weird.

The downside: the poll doesn't seem to time out when the
connect times out (Linux 3.13 x86-64).

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

index 4c84ba7ac3b1702ac0467bb7e3fd29244eecf298..7867054d9adf6c39bb48d68d8221c09c19925b86 100644 (file)
@@ -159,6 +159,9 @@ int net_connect_complete(struct pollfd pfds[2])
                        }
                        continue;
                }
+               if (!(pfds[i].revents & POLLOUT))
+                       continue;
+
                if (getsockopt(pfds[i].fd, SOL_SOCKET, SO_ERROR, &err,
                               &errlen) != 0) {
                        net_connect_abort(pfds);