Commit ad362fc1c3560fbd88d09c7e59da83daaa2834c4

Authored by Julian Raschke
Committed by Stéphane Raimbault
1 parent db3b8525

Use nonblocking sockets on Win32 and OS X/iOS too

Showing 1 changed file with 13 additions and 0 deletions
src/modbus-tcp.c
... ... @@ -218,6 +218,19 @@ static int _modbus_tcp_set_ipv4_options(int s)
218 218 return -1;
219 219 }
220 220  
  221 + /* If the OS does not offer SOCK_NONBLOCK, fall back to setting FIONBIO to make sockets non-blocking */
  222 + /* Do not care about the return value, this is optional */
  223 +#if !defined(SOCK_NONBLOCK) && defined(FIONBIO)
  224 +#ifdef OS_WIN32
  225 + /* Setting FIONBIO expects an unsigned long according to MSDN */
  226 + unsigned long ioctloption = 1;
  227 + ioctlsocket(s, FIONBIO, &ioctloption);
  228 +#else
  229 + option = 1;
  230 + ioctl(s, FIONBIO, &option);
  231 +#endif
  232 +#endif
  233 +
221 234 #ifndef OS_WIN32
222 235 /**
223 236 * Cygwin defines IPTOS_LOWDELAY but can't handle that flag so it's
... ...