diff --git a/sc2/src/sc2code/libs/network/connect/connect.c b/sc2/src/sc2code/libs/network/connect/connect.c index 339045792..76bb0e8fd 100644 --- a/sc2/src/sc2code/libs/network/connect/connect.c +++ b/sc2/src/sc2code/libs/network/connect/connect.c @@ -132,7 +132,6 @@ ConnectState_getExtra(ConnectState *connectState) { return connectState->extra; } -// Try connecting to the next address. static void connectCallback(NetDescriptor *nd) { // Called by the NetManager when a connection has been established. @@ -207,6 +206,7 @@ setConnectTimeout(ConnectState *connectState) { (AlarmCallback) connectTimeoutCallback, connectState); } +// Try connecting to the next address. static Socket * tryConnectHostNext(ConnectState *connectState) { struct addrinfo *info; diff --git a/sc2/src/sc2code/libs/network/netmanager/netmanager_win.c b/sc2/src/sc2code/libs/network/netmanager/netmanager_win.c index caa1e0cb6..b884fde04 100644 --- a/sc2/src/sc2code/libs/network/netmanager/netmanager_win.c +++ b/sc2/src/sc2code/libs/network/netmanager/netmanager_win.c @@ -112,7 +112,7 @@ NetManager_addDesc(NetDescriptor *nd) { eventMask |= FD_READ | FD_ACCEPT; if (nd->writeCallback != NULL) - eventMask |= FD_WRITE | FD_CONNECT; + eventMask |= FD_WRITE /* | FD_CONNECT */; if (nd->exceptionCallback != NULL) eventMask |= FD_OOB; @@ -299,12 +299,12 @@ NetManager_deactivateReadCallback(NetDescriptor *nd) { void NetManager_activateWriteCallback(NetDescriptor *nd) { - activateSomeCallback(nd, FD_WRITE | FD_CONNECT); + activateSomeCallback(nd, FD_WRITE /* | FD_CONNECT */); } void NetManager_deactivateWriteCallback(NetDescriptor *nd) { - deactivateSomeCallback(nd, FD_WRITE | FD_CONNECT); + deactivateSomeCallback(nd, FD_WRITE /* | FD_CONNECT */); } void @@ -376,6 +376,9 @@ NetManager_processEvent(size_t index) { if (closed) goto closed; } +#if 0 + // No need for this. Windows also sets FD_WRITE in this case, and + // writability is what we check for anyhow. if (networkEvents.lNetworkEvents & FD_CONNECT) { // There is no specific connect callback (because the BSD sockets // don't work with specific notification for connect); we use @@ -390,6 +393,7 @@ NetManager_processEvent(size_t index) { if (closed) goto closed; } +#endif if (networkEvents.lNetworkEvents & FD_CLOSE) { // The close event is handled last, in case there was still // data in the buffers which could be processed. diff --git a/sc2/src/sc2code/libs/network/netport.h b/sc2/src/sc2code/libs/network/netport.h index 2cd344a19..a158c3bef 100644 --- a/sc2/src/sc2code/libs/network/netport.h +++ b/sc2/src/sc2code/libs/network/netport.h @@ -21,7 +21,7 @@ #include "port.h" -#if defined (USE_WINSOCK) +#ifdef USE_WINSOCK int winsockErrorToErrno(int winsockError); int getWinsockErrno(void); # define EAI_SYSTEM 0x02000001 diff --git a/sc2/src/sc2code/libs/network/socket/socket_win.c b/sc2/src/sc2code/libs/network/socket/socket_win.c index af57173e9..4b011ea7e 100644 --- a/sc2/src/sc2code/libs/network/socket/socket_win.c +++ b/sc2/src/sc2code/libs/network/socket/socket_win.c @@ -88,6 +88,13 @@ Socket_connect(Socket *sock, const struct sockaddr *addr, errno = getWinsockErrno(); } while (errno == EINTR); + if (errno == EWOULDBLOCK) { + // Windows returns (WSA)EWOULDBLOCK when a connection is being + // initiated on a non-blocking socket, while other platforms + // use EINPROGRESS in such cases. + errno = EINPROGRESS; + } + return -1; }