From ad362fc1c3560fbd88d09c7e59da83daaa2834c4 Mon Sep 17 00:00:00 2001 From: Julian Raschke Date: Mon, 17 Dec 2012 01:03:21 +1000 Subject: [PATCH] Use nonblocking sockets on Win32 and OS X/iOS too --- src/modbus-tcp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+), 0 deletions(-) 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 -- libgit2 0.21.4