Browse Source

Fix TCP IPv4 modbus_connect() on win32 (closes #100 and #165)

Thank you Petr Gladkiy and MarjanTomas.
Sorry for the delay...
Stéphane Raimbault 11 năm trước cách đây
mục cha
commit
706fa6b292
1 tập tin đã thay đổi với 9 bổ sung2 xóa
  1. 9 2
      src/modbus-tcp.c

+ 9 - 2
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;