]> Zhao Yanbai Git Server - minix.git/commitdiff
Nonblocking connect for TCP sockets.
authorPhilip Homburg <philip@cs.vu.nl>
Fri, 30 Sep 2005 12:50:50 +0000 (12:50 +0000)
committerPhilip Homburg <philip@cs.vu.nl>
Fri, 30 Sep 2005 12:50:50 +0000 (12:50 +0000)
lib/ip/connect.c

index 72f1a18cb6e3dd1efc10db2d35d95488b01b3ada..f1ae13d588a5017d7fec199b05084f5d6b467701 100644 (file)
@@ -1,4 +1,5 @@
 #include <errno.h>
+#include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/ioctl.h>
@@ -79,9 +80,21 @@ static int _tcp_connect(int socket, const struct sockaddr *address,
        tcpconf.nwtc_remport= sinp->sin_port;
 
        if (ioctl(socket, NWIOSTCPCONF, &tcpconf) == -1)
-               return -1;
+        {
+               /* Ignore EISCONN error. The NWIOTCPCONN ioctl will get the
+                * right error.
+                */
+               if (errno != EISCONN)
+                       return -1;
+       }
 
-       tcpcl.nwtcl_flags= 0;
+       tcpcl.nwtcl_flags= TCF_DEFAULT;
+
+       r= fcntl(socket, F_GETFL);
+       if (r == 1)
+               return -1;
+       if (r & O_NONBLOCK)
+               tcpcl.nwtcl_flags |= TCF_ASYNCH;
 
        r= ioctl(socket, NWIOTCPCONN, &tcpcl);
        return r;