X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/bc06669bcf2c0d331e231d18c0e14023433f9e79..f9520103d3b3a1a36fdb30a46aa4f6c1cd3f1c9e:/unix/uxnet.c diff --git a/unix/uxnet.c b/unix/uxnet.c index 45ea55df..02894bd9 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -390,6 +390,11 @@ int sk_address_is_local(SockAddr addr) } } +int sk_address_is_special_local(SockAddr addr) +{ + return addr->superfamily == UNIX; +} + int sk_addrtype(SockAddr addr) { SockAddrStep step; @@ -535,7 +540,7 @@ static int try_connect(Actual_Socket sock) const union sockaddr_union *sa; int err = 0; short localport; - int fl, salen, family; + int salen, family; /* * Remove the socket from the tree before we overwrite its @@ -567,17 +572,32 @@ static int try_connect(Actual_Socket sock) if (sock->oobinline) { int b = TRUE; - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (void *) &b, sizeof(b)); + if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, + (void *) &b, sizeof(b)) < 0) { + err = errno; + close(s); + goto ret; + } } if (sock->nodelay) { int b = TRUE; - setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (void *) &b, sizeof(b)); + if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, + (void *) &b, sizeof(b)) < 0) { + err = errno; + close(s); + goto ret; + } } if (sock->keepalive) { int b = TRUE; - setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *) &b, sizeof(b)); + if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, + (void *) &b, sizeof(b)) < 0) { + err = errno; + close(s); + goto ret; + } } /* @@ -675,9 +695,7 @@ static int try_connect(Actual_Socket sock) exit(1); /* XXX: GCC doesn't understand assert() on some systems. */ } - fl = fcntl(s, F_GETFL); - if (fl != -1) - fcntl(s, F_SETFL, fl | O_NONBLOCK); + nonblock(s); if ((connect(s, &(sa->sa), salen)) < 0) { if ( errno != EINPROGRESS ) { @@ -830,7 +848,12 @@ Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, i ret->oobinline = 0; - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on)); + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, + (const char *)&on, sizeof(on)) < 0) { + ret->error = strerror(errno); + close(s); + return (Socket) ret; + } retcode = -1; addr = NULL; addrlen = -1; /* placate optimiser */ @@ -1048,6 +1071,16 @@ void try_send(Actual_Socket s) * plug_closing()) at some suitable future moment. */ s->pending_error = err; + /* + * Immediately cease selecting on this socket, so that + * we don't tight-loop repeatedly trying to do + * whatever it was that went wrong. + */ + uxsel_tell(s); + /* + * Notify the front end that it might want to call us. + */ + frontend_net_error_pending(); return; } } else { @@ -1220,7 +1253,6 @@ static int net_select_result(int fd, int event) union sockaddr_union su; socklen_t addrlen = sizeof(su); int t; /* socket of connection */ - int fl; memset(&su, 0, addrlen); t = accept(s->s, &su.sa, &addrlen); @@ -1228,9 +1260,7 @@ static int net_select_result(int fd, int event) break; } - fl = fcntl(t, F_GETFL); - if (fl != -1) - fcntl(t, F_SETFL, fl | O_NONBLOCK); + nonblock(t); if (s->localhost_only && !sockaddr_is_loopback(&su.sa)) { @@ -1414,15 +1444,17 @@ static void sk_tcp_set_frozen(Socket sock, int is_frozen) static void uxsel_tell(Actual_Socket s) { int rwx = 0; - if (s->listener) { - rwx |= 1; /* read == accept */ - } else { - if (!s->connected) - rwx |= 2; /* write == connect */ - if (s->connected && !s->frozen && !s->incomingeof) - rwx |= 1 | 4; /* read, except */ - if (bufchain_size(&s->output_data)) - rwx |= 2; /* write */ + if (!s->pending_error) { + if (s->listener) { + rwx |= 1; /* read == accept */ + } else { + if (!s->connected) + rwx |= 2; /* write == connect */ + if (s->connected && !s->frozen && !s->incomingeof) + rwx |= 1 | 4; /* read, except */ + if (bufchain_size(&s->output_data)) + rwx |= 2; /* write */ + } } uxsel_set(s->s, rwx, net_select_result); }