Translate socket error to match .NET
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 26 Aug 2010 18:10:56 +0000 (14:10 -0400)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 26 Aug 2010 18:10:56 +0000 (14:10 -0400)
send(2) does not return ETIMEDOUT for a blocking socket with a write
timeout set, which causes the wrong error code to be reported to the
managed world.
Fixes bug #599488.

mono/io-layer/sockets.c

index f2221767a49004291c4a288055ae77e6d4837b98..2a88bd49ed7a7ea0a10abdd5be36a88a3f65114c 100644 (file)
@@ -716,6 +716,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
 
+               /* At least linux returns EAGAIN/EWOULDBLOCK when the timeout has been set on
+                * a blocking socket. See bug #599488 */
+               if (errnum == EAGAIN) {
+                       gboolean nonblock;
+
+                       ret = ioctlsocket (fd, FIONBIO, (gulong *) &nonblock);
+                       if (ret != SOCKET_ERROR && !nonblock)
+                               errnum = ETIMEDOUT;
+               }
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);