From 051dd7898d64b5371c9c1f56858a4856c1a2e042 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 9 Jan 2003 18:14:24 +0000 Subject: [PATCH] Support asynchronous connect() in Unix networking. Now a port forwarding to a nonexistent host shouldn't hold up the rest of the program. git-svn-id: svn://svn.tartarus.org/sgt/putty@2514 cda61777-01e9-0310-a592-d414129be87e --- unix/uxnet.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/unix/uxnet.c b/unix/uxnet.c index 82b413dc..26f32be3 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -490,6 +490,11 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline, a.sin_port = htons((short) port); } + { + int i = 1; + ioctl(s, FIONBIO, &i); + } + if (( #ifdef IPV6 connect(s, ((addr->family == AF_INET6) ? @@ -499,13 +504,7 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline, connect(s, (struct sockaddr *) &a, sizeof(a)) #endif ) < 0) { - /* - * FIXME: We are prepared to receive EWOULDBLOCK here, - * because we might want the connection to be made - * asynchronously; but how do we actually arrange this in - * Unix? I forget. - */ - if ( errno != EWOULDBLOCK ) { + if ( errno != EINPROGRESS ) { ret->error = error_string(errno); return (Socket) ret; } @@ -782,11 +781,6 @@ int select_result(int fd, int event) noise_ultralight(event); switch (event) { -#ifdef FIXME_NONBLOCKING_CONNECTIONS - case FIXME: /* connected */ - s->connected = s->writable = 1; - break; -#endif case 4: /* exceptional */ if (!s->oobinline) { /* @@ -883,7 +877,14 @@ int select_result(int fd, int event) } break; case 2: /* writable */ - { + if (!s->connected) { + /* + * select() reports a socket as _writable_ when an + * asynchronous connection is completed. + */ + s->connected = s->writable = 1; + break; + } else { int bufsize_before, bufsize_after; s->writable = 1; bufsize_before = s->sending_oob + bufchain_size(&s->output_data); @@ -988,6 +989,8 @@ static void sk_tcp_set_frozen(Socket sock, int is_frozen) static void set_rwx(Actual_Socket s, int *rwx) { int val = 0; + if (!s->connected) + val |= 2; /* write == connect */ if (s->connected && !s->frozen) val |= 1 | 4; /* read, except */ if (bufchain_size(&s->output_data)) -- 2.11.0