From 1508814b3a19f568cb7cd91f4f1d32b0e3240152 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sun, 10 Jun 2018 21:59:08 +0300 Subject: [PATCH] fix (?) work with nonblocking socket for Windows read https://msdn.microsoft.com/en-us/library/windows/desktop/ms737625%28v=vs.85%29.aspx from: With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. In this case, there are three possible scenarios: [Solution] Use the select function to determine the completion of the connection request by checking to see if the socket is writeable. What exactly do we do below ... calls to `select`. --- iguana/exchanges/LP_socket.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index d7e7f03ce..13b84d272 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -57,9 +57,15 @@ int32_t komodo_connect(int32_t sock,struct sockaddr *saddr,socklen_t addrlen) fcntl(sock, F_SETFL, O_NONBLOCK); #endif // _WIN32 res = connect(sock,saddr,addrlen); + if ( res == -1 ) { - if ( errno != EINPROGRESS ) // connect failed, do something... +#ifdef _WIN32 + // https://msdn.microsoft.com/en-us/library/windows/desktop/ms737625%28v=vs.85%29.aspx - read about WSAEWOULDBLOCK return + if (!(( errno == EINPROGRESS) || ( errno = WSAEWOULDBLOCK))) // connect failed, do something... +#else + if (errno != EINPROGRESS) // connect failed, do something... +#endif { closesocket(sock); return(-1);