Merge remote branch 'upstream/master'
[mono.git] / mono / io-layer / sockets.c
index f2221767a49004291c4a288055ae77e6d4837b98..c068f06281d7794ba5f88e7058b10a59a00883cc 100644 (file)
@@ -7,9 +7,10 @@
  * (C) 2002 Ximian, Inc.
  */
 
+#include <config.h>
+
 #ifndef DISABLE_SOCKETS
 
-#include <config.h>
 #include <glib.h>
 #include <pthread.h>
 #include <errno.h>
@@ -716,6 +717,15 @@ int _wapi_send(guint32 fd, const void *msg, size_t len, int send_flags)
                g_message ("%s: send error: %s", __func__, strerror (errno));
 #endif
 
+#ifdef O_NONBLOCK
+               /* At least linux returns EAGAIN/EWOULDBLOCK when the timeout has been set on
+                * a blocking socket. See bug #599488 */
+               if (errnum == EAGAIN) {
+                       ret = fcntl (fd, F_GETFL, 0);
+                       if (ret != -1 && (ret & O_NONBLOCK) == 0)
+                               errnum = ETIMEDOUT;
+               }
+#endif /* O_NONBLOCK */
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);