Browse Source

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`.
pass-iguana-arg
DeckerSU 7 years ago
parent
commit
1508814b3a
  1. 8
      iguana/exchanges/LP_socket.c

8
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);

Loading…
Cancel
Save