From: Ludovic Henry Date: Wed, 7 Oct 2015 15:33:14 +0000 (+0100) Subject: [socket] Shutdown socket before trying to abort syscall X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=12a58743fc29bec8fb605d49c251bd0f6ade55fe;p=mono.git [socket] Shutdown socket before trying to abort syscall 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. --- diff --git a/mcs/class/System/System.Net.Sockets/SafeSocketHandle.cs b/mcs/class/System/System.Net.Sockets/SafeSocketHandle.cs index 00f14114077..0726107ace0 100644 --- a/mcs/class/System/System.Net.Sockets/SafeSocketHandle.cs +++ b/mcs/class/System/System.Net.Sockets/SafeSocketHandle.cs @@ -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; diff --git a/mcs/class/System/System.Net.Sockets/Socket.cs b/mcs/class/System/System.Net.Sockets/Socket.cs index 1086f4f17a2..41fe152725b 100644 --- a/mcs/class/System/System.Net.Sockets/Socket.cs +++ b/mcs/class/System/System.Net.Sockets/Socket.cs @@ -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