From: Philip Homburg Date: Fri, 30 Sep 2005 12:50:50 +0000 (+0000) Subject: Nonblocking connect for TCP sockets. X-Git-Tag: v3.1.2a~687 X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=731eee27c3b5bbbf3e08267485b33a19d6462afc;p=minix.git Nonblocking connect for TCP sockets. --- diff --git a/lib/ip/connect.c b/lib/ip/connect.c index 72f1a18cb..f1ae13d58 100644 --- a/lib/ip/connect.c +++ b/lib/ip/connect.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -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;