[runtime] Fixed interruptible wapi_sendfile.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Tue, 7 Jun 2016 13:06:53 +0000 (14:06 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Tue, 7 Jun 2016 13:25:04 +0000 (14:25 +0100)
Before closing a socket we try to interrupt and wait for all socket
pending system calls to return. For that we set the socket as non
blocking which makes the system calls to return with EAGAIN\EWOULDBLOCK.

This issue was caught by System.Net.Sockets.SocketTest.SendAsyncFile
that was intermittently failing, we were only able to reproduce it while
running multiple test suites in parallel. We now can say that it only failed when
the the socket was closed and the sendfile was waiting for the OS to
allocate enough resources to send the file.

This was fixed by changing wapi_sendfile to return on EAGAIN.

mono/io-layer/sockets.c

index aaa53ffe16d157b16554960ba51f2ab35c430ab8..6d0da527bd65c54a31c77c2f1b0255c0d43add1a 100644 (file)
@@ -969,7 +969,7 @@ wapi_sendfile (guint32 socket, gpointer fd, guint32 bytes_to_write, guint32 byte
                /* TODO: Might not send the entire file for non-blocking sockets */
                res = sendfile (file, socket, 0, &statbuf.st_size, NULL, 0);
 #endif
-       } while (res != -1 && (errno == EINTR || errno == EAGAIN) && !_wapi_thread_cur_apc_pending ());
+       } while (res != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
        if (res == -1) {
                errnum = errno;
                errnum = errno_to_WSA (errnum, __func__);