X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/b72210b4ea15082225a2546a1175dd0f6389c3f3..b44d65f497c35fe7684a2e7e7a3085c4c7c80131:/windows/winnet.c diff --git a/windows/winnet.c b/windows/winnet.c index f8838bec..89d2f474 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -96,6 +96,10 @@ static int cmpfortree(void *av, void *bv) return -1; if (as > bs) return +1; + if (a < b) + return -1; + if (a > b) + return +1; return 0; } @@ -788,6 +792,14 @@ static DWORD try_connect(Actual_Socket sock) family = AF_INET; } + /* + * Remove the socket from the tree before we overwrite its + * internal socket id, because that forms part of the tree's + * sorting criterion. We'll add it back before exiting this + * function, whether we changed anything or not. + */ + del234(sktree, sock); + s = p_socket(family, SOCK_STREAM, 0); sock->s = s; @@ -932,11 +944,15 @@ static DWORD try_connect(Actual_Socket sock) sock->writable = 1; } - add234(sktree, sock); - err = 0; ret: + + /* + * No matter what happened, put the socket back in the tree. + */ + add234(sktree, sock); + if (err) plug_log(sock->plug, 1, sock->addr, sock->port, sock->error, err); return err; @@ -1473,10 +1489,11 @@ int select_result(WPARAM wParam, LPARAM lParam) #ifndef NO_IPV6 if (isa.ss_family == AF_INET && s->localhost_only && - !ipv4_is_local_addr(((struct sockaddr_in *)&isa)->sin_addr)) { + !ipv4_is_local_addr(((struct sockaddr_in *)&isa)->sin_addr)) #else - if (s->localhost_only && !ipv4_is_local_addr(isa.sin_addr)) { + if (s->localhost_only && !ipv4_is_local_addr(isa.sin_addr)) #endif + { p_closesocket(t); /* dodgy WinSock let nonlocal through */ } else if (plug_accepting(s->plug, (void*)t)) { p_closesocket(t); /* denied or error */ @@ -1572,6 +1589,17 @@ static void sk_tcp_set_frozen(Socket sock, int is_frozen) s->frozen_readable = 0; } +void socket_reselect_all(void) +{ + Actual_Socket s; + int i; + + for (i = 0; (s = index234(sktree, i)) != NULL; i++) { + if (!s->frozen) + do_select(s->s, 1); + } +} + /* * For Plink: enumerate all sockets currently active. */ @@ -1609,7 +1637,8 @@ int net_service_lookup(char *service) return 0; } -SockAddr platform_get_x11_unix_address(int displaynum, char **canonicalname) +SockAddr platform_get_x11_unix_address(const char *display, int displaynum, + char **canonicalname) { SockAddr ret = snew(struct SockAddr_tag); memset(ret, 0, sizeof(struct SockAddr_tag));