[Socket] Move SendFile related methods to their region
authorLudovic Henry <ludovic.henry@xamarin.com>
Thu, 9 Apr 2015 09:53:34 +0000 (10:53 +0100)
committerLudovic Henry <ludovic.henry@xamarin.com>
Thu, 9 Apr 2015 13:37:21 +0000 (14:37 +0100)
mcs/class/System/System.Net.Sockets/Socket.cs
mono/metadata/icall-def.h
mono/metadata/socket-io.c
mono/metadata/socket-io.h

index 379a52ac18f1d8b3a4ab0596d8ecd77fb3417c29..347a2cd2fc07ad0406312df37bbaba76aa2f9fc9 100644 (file)
@@ -2491,18 +2491,90 @@ namespace System.Net.Sockets
 
 #endregion
 
-               void CheckRange (byte[] buffer, int offset, int size)
+#region SendFile
+
+               public void SendFile (string fileName)
                {
-                       if (offset < 0)
-                               throw new ArgumentOutOfRangeException ("offset", "offset must be >= 0");
-                       if (offset > buffer.Length)
-                               throw new ArgumentOutOfRangeException ("offset", "offset must be <= buffer.Length");
-                       if (size < 0)
-                               throw new ArgumentOutOfRangeException ("size", "size must be >= 0");
-                       if (size > buffer.Length - offset)
-                               throw new ArgumentOutOfRangeException ("size", "size must be <= buffer.Length - offset");
+                       ThrowIfDisposedAndClosed ();
+
+                       if (!is_connected)
+                               throw new NotSupportedException ();
+                       if (!is_blocking)
+                               throw new InvalidOperationException ();
+
+                       SendFile (fileName, null, null, 0);
+               }
+
+               public void SendFile (string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
+               {
+                       ThrowIfDisposedAndClosed ();
+
+                       if (!is_connected)
+                               throw new NotSupportedException ();
+                       if (!is_blocking)
+                               throw new InvalidOperationException ();
+
+                       if (!SendFile_internal (safe_handle, fileName, preBuffer, postBuffer, flags)) {
+                               SocketException exc = new SocketException ();
+                               if (exc.ErrorCode == 2 || exc.ErrorCode == 3)
+                                       throw new FileNotFoundException ();
+                               throw exc;
+                       }
+               }
+
+               public IAsyncResult BeginSendFile (string fileName, AsyncCallback callback, object state)
+               {
+                       ThrowIfDisposedAndClosed ();
+
+                       if (!is_connected)
+                               throw new NotSupportedException ();
+                       if (!File.Exists (fileName))
+                               throw new FileNotFoundException ();
+
+                       return BeginSendFile (fileName, null, null, 0, callback, state);
+               }
+
+               public IAsyncResult BeginSendFile (string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags, AsyncCallback callback, object state)
+               {
+                       ThrowIfDisposedAndClosed ();
+
+                       if (!is_connected)
+                               throw new NotSupportedException ();
+                       if (!File.Exists (fileName))
+                               throw new FileNotFoundException ();
+
+                       SendFileHandler handler = new SendFileHandler (SendFile);
+
+                       return new SendFileAsyncResult (handler, handler.BeginInvoke (fileName, preBuffer, postBuffer, flags, ar => callback (new SendFileAsyncResult (handler, ar)), state));
                }
 
+               public void EndSendFile (IAsyncResult asyncResult)
+               {
+                       ThrowIfDisposedAndClosed ();
+
+                       if (asyncResult == null)
+                               throw new ArgumentNullException ("asyncResult");
+
+                       SendFileAsyncResult ares = asyncResult as SendFileAsyncResult;
+                       if (ares == null)
+                               throw new ArgumentException ("Invalid IAsyncResult", "asyncResult");
+
+                       ares.Delegate.EndInvoke (ares.Original);
+               }
+
+               static bool SendFile_internal (SafeSocketHandle safeHandle, string filename, byte [] pre_buffer, byte [] post_buffer, TransmitFileOptions flags)
+               {
+                       try {
+                               safeHandle.RegisterForBlockingSyscall ();
+                               return SendFile_internal (safeHandle.DangerousGetHandle (), filename, pre_buffer, post_buffer, flags);
+                       } finally {
+                               safeHandle.UnRegisterForBlockingSyscall ();
+                       }
+               }
+
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               extern static bool SendFile_internal (IntPtr sock, string filename, byte [] pre_buffer, byte [] post_buffer, TransmitFileOptions flags);
+
                delegate void SendFileHandler (string fileName, byte [] preBuffer, byte [] postBuffer, TransmitFileOptions flags);
 
                sealed class SendFileAsyncResult : IAsyncResult {
@@ -2540,43 +2612,18 @@ namespace System.Net.Sockets
                        }
                }
 
-               public IAsyncResult BeginSendFile (string fileName,
-                                                  AsyncCallback callback,
-                                                  object state)
-               {
-                       if (is_disposed && is_closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (!is_connected)
-                               throw new NotSupportedException ();
-
-                       if (!File.Exists (fileName))
-                               throw new FileNotFoundException ();
-
-                       return BeginSendFile (fileName, null, null, 0, callback, state);
-               }
+#endregion
 
-               public IAsyncResult BeginSendFile (string fileName,
-                                                  byte[] preBuffer,
-                                                  byte[] postBuffer,
-                                                  TransmitFileOptions flags,
-                                                  AsyncCallback callback,
-                                                  object state)
+               void CheckRange (byte[] buffer, int offset, int size)
                {
-                       if (is_disposed && is_closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (!is_connected)
-                               throw new NotSupportedException ();
-
-                       if (!File.Exists (fileName))
-                               throw new FileNotFoundException ();
-
-                       SendFileHandler d = new SendFileHandler (SendFile);
-                       return new SendFileAsyncResult (d, d.BeginInvoke (fileName, preBuffer, postBuffer, flags, ar => {
-                               SendFileAsyncResult sfar = new SendFileAsyncResult (d, ar);
-                               callback (sfar);
-                       }, state));
+                       if (offset < 0)
+                               throw new ArgumentOutOfRangeException ("offset", "offset must be >= 0");
+                       if (offset > buffer.Length)
+                               throw new ArgumentOutOfRangeException ("offset", "offset must be <= buffer.Length");
+                       if (size < 0)
+                               throw new ArgumentOutOfRangeException ("size", "size must be >= 0");
+                       if (size > buffer.Length - offset)
+                               throw new ArgumentOutOfRangeException ("size", "size must be <= buffer.Length - offset");
                }
 
                // Creates a new system socket, returning the handle
@@ -2638,22 +2685,6 @@ namespace System.Net.Sockets
                }
 #endif
 
-
-               public void EndSendFile (IAsyncResult asyncResult)
-               {
-                       if (is_disposed && is_closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (asyncResult == null)
-                               throw new ArgumentNullException ("asyncResult");
-
-                       SendFileAsyncResult ares = asyncResult as SendFileAsyncResult;
-                       if (ares == null)
-                               throw new ArgumentException ("Invalid IAsyncResult", "asyncResult");
-
-                       ares.Delegate.EndInvoke (ares.Original);
-               }
-
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern static void GetSocketOption_arr_internal(IntPtr socket,
                        SocketOptionLevel level, SocketOptionName name, ref byte[] byte_val,
@@ -2825,54 +2856,6 @@ namespace System.Net.Sockets
                        throw new NotImplementedException ();
                }
 
-
-
-               [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern static bool SendFile (IntPtr sock, string filename, byte [] pre_buffer, byte [] post_buffer, TransmitFileOptions flags);
-
-               private static bool SendFile (SafeSocketHandle safeHandle, string filename, byte [] pre_buffer, byte [] post_buffer, TransmitFileOptions flags)
-               {
-                       try {
-                               safeHandle.RegisterForBlockingSyscall ();
-                               return SendFile (safeHandle.DangerousGetHandle (), filename, pre_buffer, post_buffer, flags);
-                       } finally {
-                               safeHandle.UnRegisterForBlockingSyscall ();
-                       }
-               }
-
-               public void SendFile (string fileName)
-               {
-                       if (is_disposed && is_closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (!is_connected)
-                               throw new NotSupportedException ();
-
-                       if (!is_blocking)
-                               throw new InvalidOperationException ();
-
-                       SendFile (fileName, null, null, 0);
-               }
-
-               public void SendFile (string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
-               {
-                       if (is_disposed && is_closed)
-                               throw new ObjectDisposedException (GetType ().ToString ());
-
-                       if (!is_connected)
-                               throw new NotSupportedException ();
-
-                       if (!is_blocking)
-                               throw new InvalidOperationException ();
-
-                       if (!SendFile (safe_handle, fileName, preBuffer, postBuffer, flags)) {
-                               SocketException exc = new SocketException ();
-                               if (exc.ErrorCode == 2 || exc.ErrorCode == 3)
-                                       throw new FileNotFoundException ();
-                               throw exc;
-                       }
-               }
-
                public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, byte [] optionValue)
                {
                        if (is_disposed && is_closed)
index 4b9daf38020910f04620b89d07c3b7bdf33fd169..bbf35a116c60d3e84df8cab9849cefe440efd266 100644 (file)
@@ -434,7 +434,7 @@ ICALL(SOCK_11a, "Receive_internal(intptr,System.Net.Sockets.Socket/WSABUF[],Syst
 ICALL(SOCK_12, "Receive_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Receive_internal)
 ICALL(SOCK_14, "RemoteEndPoint_internal(intptr,int,int&)", ves_icall_System_Net_Sockets_Socket_RemoteEndPoint_internal)
 ICALL(SOCK_15, "Select_internal(System.Net.Sockets.Socket[]&,int,int&)", ves_icall_System_Net_Sockets_Socket_Select_internal)
-ICALL(SOCK_15a, "SendFile(intptr,string,byte[],byte[],System.Net.Sockets.TransmitFileOptions)", ves_icall_System_Net_Sockets_Socket_SendFile)
+ICALL(SOCK_15a, "SendFile_internal(intptr,string,byte[],byte[],System.Net.Sockets.TransmitFileOptions)", ves_icall_System_Net_Sockets_Socket_SendFile_internal)
 ICALL(SOCK_16, "SendTo_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress,int&)", ves_icall_System_Net_Sockets_Socket_SendTo_internal)
 ICALL(SOCK_16a, "Send_internal(intptr,System.Net.Sockets.Socket/WSABUF[],System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_array_internal)
 ICALL(SOCK_17, "Send_internal(intptr,byte[],int,int,System.Net.Sockets.SocketFlags,int&)", ves_icall_System_Net_Sockets_Socket_Send_internal)
index a7cfbd9b2787d83613e67b8c1141401a2ba358f9..9b42227b79590e5264f078c6bd1b719789398da0 100644 (file)
@@ -2467,7 +2467,7 @@ extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_
 }
 
 gboolean
-ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags)
+ves_icall_System_Net_Sockets_Socket_SendFile_internal (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags)
 {
        HANDLE file;
        gint32 error;
index 09aeba3c786e6ce33bd7d5e62b8fe09f1bac1470..5e11f21d85586e4de34db03a411a54a36fe667b4 100644 (file)
@@ -219,7 +219,7 @@ extern MonoBoolean ves_icall_System_Net_Dns_GetHostByAddr_internal(MonoString *a
 extern MonoBoolean ves_icall_System_Net_Dns_GetHostName_internal(MonoString **h_name);
 extern MonoBoolean ves_icall_System_Net_Sockets_Socket_Poll_internal (SOCKET sock, gint mode, gint timeout, gint32 *error);
 extern void ves_icall_System_Net_Sockets_Socket_Disconnect_internal(SOCKET sock, MonoBoolean reuse, gint32 *error);
-extern gboolean ves_icall_System_Net_Sockets_Socket_SendFile (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags);
+extern gboolean ves_icall_System_Net_Sockets_Socket_SendFile_internal (SOCKET sock, MonoString *filename, MonoArray *pre_buffer, MonoArray *post_buffer, gint flags);
 void icall_cancel_blocking_socket_operation (MonoThread *thread);
 
 extern void mono_network_init(void);