Commit 706fa6b2920953c4a5cc07f261ab82af21e3e0ee

Authored by Stéphane Raimbault
1 parent 7272fb09

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

Thank you Petr Gladkiy and MarjanTomas.
Sorry for the delay...
Showing 1 changed file with 9 additions and 2 deletions
src/modbus-tcp.c
... ... @@ -268,11 +268,18 @@ static int _connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen,
268 268 {
269 269 int rc;
270 270  
  271 +#ifdef OS_WIN32
  272 + int wsaError = 0;
  273 +
271 274 rc = connect(sockfd, addr, addrlen);
  275 + if (rc == -1) {
  276 + wsaError = WSAGetLastError();
  277 + }
272 278  
273   -#ifdef OS_WIN32
274   - if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {
  279 + if (wsaError == WSAEWOULDBLOCK || wsaError == WSAEINPROGRESS) {
275 280 #else
  281 +
  282 + rc = connect(sockfd, addr, addrlen);
276 283 if (rc == -1 && errno == EINPROGRESS) {
277 284 #endif
278 285 fd_set wset;
... ...