[socket] Shutdown socket before trying to abort syscall
authorLudovic Henry <ludovic@xamarin.com>
Wed, 7 Oct 2015 15:33:14 +0000 (16:33 +0100)
committerLudovic Henry <ludovic@xamarin.com>
Wed, 7 Oct 2015 16:44:30 +0000 (17:44 +0100)
This is useful on WatchOS and TvOS as it's the only two platforms that
do not support signal based syscall abort. By calling shutdown, the
blocking syscalls on other threads will be interrupted. All the other
platforms currently support signals, so this will not change anything.

We cannot call Close, as this would let the OS reuse the FD for
something else, and the call to Receive (for example) on another thread
could fail with ENOTSOCK.

Unfortunatly it does not work for UDP based connection, as they are not
stream based, so Shutdown does not have much sense.

mcs/class/System/System.Net.Sockets/SafeSocketHandle.cs
mcs/class/System/System.Net.Sockets/Socket.cs

index 00f14114077d259e3d7956be41c6f2074d686e4e..0726107ace0937b4f8ebd956fcc05ac0900c3068 100644 (file)
@@ -37,6 +37,7 @@ namespace System.Net.Sockets {
                        int error = 0;
 
                        Socket.Blocking_internal (handle, false, out error);
+                       Socket.Shutdown_internal (handle, SocketShutdown.Both, out error);
 
                        if (blocking_threads != null) {
                                int abort_attempts = 0;
index 1086f4f17a22aca5c835a0ec8e7b4834a60a5c77..41fe152725b9ed89fee335511187f1462acc4053 100644 (file)
@@ -3283,7 +3283,7 @@ namespace System.Net.Sockets
                }
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               extern static void Shutdown_internal (IntPtr socket, SocketShutdown how, out int error);
+               internal extern static void Shutdown_internal (IntPtr socket, SocketShutdown how, out int error);
 
 #endregion