Kaynağa Gözat

Use nonblocking sockets on Win32 and OS X/iOS too

Julian Raschke 12 yıl önce
ebeveyn
işleme
ad362fc1c3
1 değiştirilmiş dosya ile 13 ekleme ve 0 silme
  1. 13 0
      src/modbus-tcp.c

+ 13 - 0
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