From 731eee27c3b5bbbf3e08267485b33a19d6462afc Mon Sep 17 00:00:00 2001 From: Philip Homburg Date: Fri, 30 Sep 2005 12:50:50 +0000 Subject: [PATCH] Nonblocking connect for TCP sockets. --- lib/ip/connect.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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; -- 2.44.0