diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index 40a5eb5..c38be50 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -218,6 +218,19 @@ static int _modbus_tcp_set_ipv4_options(int s) return -1; } + /* If the OS does not offer SOCK_NONBLOCK, fall back to setting FIONBIO to make sockets non-blocking */ + /* Do not care about the return value, this is optional */ +#if !defined(SOCK_NONBLOCK) && defined(FIONBIO) +#ifdef OS_WIN32 + /* Setting FIONBIO expects an unsigned long according to MSDN */ + unsigned long ioctloption = 1; + ioctlsocket(s, FIONBIO, &ioctloption); +#else + option = 1; + ioctl(s, FIONBIO, &option); +#endif +#endif + #ifndef OS_WIN32 /** * Cygwin defines IPTOS_LOWDELAY but can't handle that flag so it's