diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index 69455e6..ebfe2df 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -268,11 +268,18 @@ static int _connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen, { int rc; +#ifdef OS_WIN32 + int wsaError = 0; + rc = connect(sockfd, addr, addrlen); + if (rc == -1) { + wsaError = WSAGetLastError(); + } -#ifdef OS_WIN32 - if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) { + if (wsaError == WSAEWOULDBLOCK || wsaError == WSAEINPROGRESS) { #else + + rc = connect(sockfd, addr, addrlen); if (rc == -1 && errno == EINPROGRESS) { #endif fd_set wset;