[referencesource] Import parts of System.Net.Sockets.Socket (#3618)
authorLudovic Henry <ludovic@xamarin.com>
Sat, 24 Sep 2016 18:10:01 +0000 (20:10 +0200)
committerGitHub <noreply@github.com>
Sat, 24 Sep 2016 18:10:01 +0000 (20:10 +0200)
mcs/class/System/ReferenceSources/Logging.cs
mcs/class/System/ReferenceSources/Socket.cs
mcs/class/System/System.Net.NetworkInformation/Ping.cs
mcs/class/System/System.Net.Sockets/Socket.cs
mcs/class/System/System.Net.Sockets/SocketAsyncResult.cs
mcs/class/System/System.dll.sources
mcs/class/System/mobile_System.dll.sources
mcs/class/referencesource/System/net/System/Net/Sockets/Socket.cs
mono/metadata/socket-io.c

index b5b773e28c4f186888e9a03b710e7524d4c66c23..cacf8e90b3266773be94b45e3e310868515559e6 100644 (file)
@@ -21,6 +21,12 @@ namespace System.Net {
                        }
                }
 
+               internal static TraceSource Sockets {
+                       get {
+                               return null;
+                       }
+               }
+
                [Conditional ("TRACE")]
                internal static void Enter(TraceSource traceSource, object obj, string method, object paramObject) {
                }
index 8c1d12b8aaaeea6744f18260c9f1db19986b9c64..b5fa6ee09e5f1dee58880f9f7a7a837a06aa7261 100644 (file)
@@ -37,10 +37,10 @@ namespace System.Net.Sockets
                // this version does not throw.
                internal void InternalShutdown (SocketShutdown how)
                {
-                       if (!is_connected || is_disposed)
+                       if (!is_connected || CleanedUp)
                                return;
                        int error;
-                       Shutdown_internal (safe_handle, how, out error);
+                       Shutdown_internal (m_Handle, how, out error);
                }
 
                internal IAsyncResult UnsafeBeginConnect (EndPoint remoteEP, AsyncCallback callback, object state)
@@ -86,7 +86,7 @@ namespace System.Net.Sockets
 
                internal void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue, bool silent)
                {
-                       if (is_disposed && is_closed) {
+                       if (CleanedUp && is_closed) {
                                if (silent)
                                        return;
                                throw new ObjectDisposedException (GetType ().ToString ());
@@ -94,7 +94,7 @@ namespace System.Net.Sockets
 
                        int error;
 
-                       SetSocketOption_internal (safe_handle, optionLevel, optionName, null,
+                       SetSocketOption_internal (m_Handle, optionLevel, optionName, null,
                                null, optionValue, out error);
 
                        if (!silent && error != 0)
index 72645bcd3a712796e6c935af1280e12d887907b9..8232a9eaac445c5a035e6bff57ab6ef45357b3ff 100644 (file)
@@ -262,12 +262,12 @@ namespace System.Net.NetworkInformation {
                                bytes = new byte [100];
                                do {
                                        EndPoint endpoint = client;
-                                       int error = 0;
-                                       int rc = s.ReceiveFrom_nochecks_exc (bytes, 0, 100, SocketFlags.None,
-                                                       ref endpoint, false, out error);
+                                       SocketError error = 0;
+                                       int rc = s.ReceiveFrom (bytes, 0, 100, SocketFlags.None,
+                                                       ref endpoint, out error);
 
-                                       if (error != 0) {
-                                               if (error == (int) SocketError.TimedOut) {
+                                       if (error != SocketError.Success) {
+                                               if (error == SocketError.TimedOut) {
                                                        return new PingReply (null, new byte [0], options, 0, IPStatus.TimedOut);
                                                }
                                                throw new NotSupportedException (String.Format ("Unexpected socket error during ping request: {0}", error));
index 92d1a32648e3c655ba4ac4b9119c0ab5c5aa3287..d17dc34f6fdaf7b7b63bb1d95b38b7a6315699ee 100644 (file)
@@ -66,16 +66,16 @@ namespace System.Net.Sockets
                bool is_closed;
 
                bool is_listening;
-               bool use_overlapped_io;
+               bool useOverlappedIO;
 
                int linger_timeout;
 
-               AddressFamily address_family;
-               SocketType socket_type;
-               ProtocolType protocol_type;
+               AddressFamily addressFamily;
+               SocketType socketType;
+               ProtocolType protocolType;
 
-               /* the field "safe_handle" is looked up by name by the runtime */
-               internal SafeSocketHandle safe_handle;
+               /* the field "m_Handle" is looked up by name by the runtime */
+               internal SafeSocketHandle m_Handle;
 
                /*
                 * This EndPoint is used when creating new endpoints. Because
@@ -95,9 +95,11 @@ namespace System.Net.Sockets
                /* When true, the socket was connected at the time of the last IO operation */
                internal bool is_connected;
 
-               internal bool is_disposed;
+               int m_IntCleanedUp;
                internal bool connect_in_progress;
 
+               private static volatile bool s_LoggingEnabled = Logging.On;
+
 #region Constructors
 
                static Socket ()
@@ -156,26 +158,14 @@ namespace System.Net.Sockets
                        }
                }
 
-               //
-               // This constructor is used by servers that want to listen for instance on both
-               // ipv4 and ipv6.   Mono has historically done that if you use InterNetworkV6 (at
-               // least on Unix), because that is the default behavior unless the IPV6_V6ONLY
-               // option is explicitly set by using setsockopt (sock, IPPROTO_IPV6, IPV6_ONLY)
-               //
-               public Socket (SocketType socketType, ProtocolType protocolType)
-                       : this (AddressFamily.InterNetworkV6, socketType, protocolType)
-               {
-                       DualMode = true;
-               }
-               
                public Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
                {
-                       this.address_family = addressFamily;
-                       this.socket_type = socketType;
-                       this.protocol_type = protocolType;
+                       this.addressFamily = addressFamily;
+                       this.socketType = socketType;
+                       this.protocolType = protocolType;
 
                        int error;
-                       this.safe_handle = new SafeSocketHandle (Socket_internal (addressFamily, socketType, protocolType, out error), true);
+                       this.m_Handle = new SafeSocketHandle (Socket_internal (addressFamily, socketType, protocolType, out error), true);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -188,15 +178,15 @@ namespace System.Net.Sockets
                        this.is_listening      = (socketInformation.Options & SocketInformationOptions.Listening) != 0;
                        this.is_connected      = (socketInformation.Options & SocketInformationOptions.Connected) != 0;
                        this.is_blocking       = (socketInformation.Options & SocketInformationOptions.NonBlocking) == 0;
-                       this.use_overlapped_io = (socketInformation.Options & SocketInformationOptions.UseOnlyOverlappedIO) != 0;
+                       this.useOverlappedIO = (socketInformation.Options & SocketInformationOptions.UseOnlyOverlappedIO) != 0;
 
                        var result = Mono.DataConverter.Unpack ("iiiil", socketInformation.ProtocolInformation, 0);
 
-                       this.address_family = (AddressFamily) (int) result [0];
-                       this.socket_type = (SocketType) (int) result [1];
-                       this.protocol_type = (ProtocolType) (int) result [2];
+                       this.addressFamily = (AddressFamily) (int) result [0];
+                       this.socketType = (SocketType) (int) result [1];
+                       this.protocolType = (ProtocolType) (int) result [2];
                        this.is_bound = (ProtocolType) (int) result [3] != 0;
-                       this.safe_handle = new SafeSocketHandle ((IntPtr) (long) result [4], true);
+                       this.m_Handle = new SafeSocketHandle ((IntPtr) (long) result [4], true);
 
                        SocketDefaults ();
                }
@@ -204,33 +194,28 @@ namespace System.Net.Sockets
                /* private constructor used by Accept, which already has a socket handle to use */
                internal Socket(AddressFamily family, SocketType type, ProtocolType proto, SafeSocketHandle safe_handle)
                {
-                       this.address_family = family;
-                       this.socket_type = type;
-                       this.protocol_type = proto;
+                       this.addressFamily = family;
+                       this.socketType = type;
+                       this.protocolType = proto;
                        
-                       this.safe_handle = safe_handle;
+                       this.m_Handle = safe_handle;
                        this.is_connected = true;
                }
 
-               ~Socket ()
-               {
-                       Dispose (false);
-               }
-
                void SocketDefaults ()
                {
                        try {
                                /* Need to test IPv6 further */
-                               if (address_family == AddressFamily.InterNetwork
-                                       // || address_family == AddressFamily.InterNetworkV6
+                               if (addressFamily == AddressFamily.InterNetwork
+                                       // || addressFamily == AddressFamily.InterNetworkV6
                                ) {
                                        /* This is the default, but it probably has nasty side
                                         * effects on Linux, as the socket option is kludged by
                                         * turning on or off PMTU discovery... */
                                        this.DontFragment = false;
-                                       if (protocol_type == ProtocolType.Tcp)
+                                       if (protocolType == ProtocolType.Tcp)
                                                this.NoDelay = false;
-                               } else if (address_family == AddressFamily.InterNetworkV6) {
+                               } else if (addressFamily == AddressFamily.InterNetworkV6) {
                                        this.DualMode = true;
                                }
 
@@ -304,7 +289,7 @@ namespace System.Net.Sockets
                                ThrowIfDisposedAndClosed ();
 
                                int ret, error;
-                               ret = Available_internal (safe_handle, out error);
+                               ret = Available_internal (m_Handle, out error);
 
                                if (error != 0)
                                        throw new SocketException (error);
@@ -329,40 +314,12 @@ namespace System.Net.Sockets
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                extern static int Available_internal (IntPtr socket, out int error);
 
-               public bool DontFragment {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               switch (address_family) {
-                               case AddressFamily.InterNetwork:
-                                       return ((int) GetSocketOption (SocketOptionLevel.IP, SocketOptionName.DontFragment)) != 0;
-                               case AddressFamily.InterNetworkV6:
-                                       return ((int) GetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DontFragment)) != 0;
-                               default:
-                                       throw new NotSupportedException ("This property is only valid for InterNetwork and InterNetworkV6 sockets");
-                               }
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               switch (address_family) {
-                               case AddressFamily.InterNetwork:
-                                       SetSocketOption (SocketOptionLevel.IP, SocketOptionName.DontFragment, value ? 1 : 0);
-                                       break;
-                               case AddressFamily.InterNetworkV6:
-                                       SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DontFragment, value ? 1 : 0);
-                                       break;
-                               default:
-                                       throw new NotSupportedException ("This property is only valid for InterNetwork and InterNetworkV6 sockets");
-                               }
-                       }
-               }
-
+               // FIXME: import from referencesource
                public bool EnableBroadcast {
                        get {
                                ThrowIfDisposedAndClosed ();
 
-                               if (protocol_type != ProtocolType.Udp)
+                               if (protocolType != ProtocolType.Udp)
                                        throw new SocketException ((int) SocketError.ProtocolOption);
 
                                return ((int) GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Broadcast)) != 0;
@@ -370,47 +327,20 @@ namespace System.Net.Sockets
                        set {
                                ThrowIfDisposedAndClosed ();
 
-                               if (protocol_type != ProtocolType.Udp)
+                               if (protocolType != ProtocolType.Udp)
                                        throw new SocketException ((int) SocketError.ProtocolOption);
 
                                SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Broadcast, value ? 1 : 0);
                        }
                }
 
-               public bool ExclusiveAddressUse {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               return ((int) GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse)) != 0;
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               if (is_bound)
-                                       throw new InvalidOperationException ("Bind has already been called for this socket");
-
-                               SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, value ? 1 : 0);
-                       }
-               }
-
                public bool IsBound {
                        get {
                                return is_bound;
                        }
                }
 
-               public LingerOption LingerState {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               return (LingerOption) GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger);
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-                               SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger, value);
-                       }
-               }
-
+               // FIXME: import from referencesource
                public bool MulticastLoopback {
                        get {
                                ThrowIfDisposedAndClosed ();
@@ -420,10 +350,10 @@ namespace System.Net.Sockets
                                 * "Setting this property on a Transmission Control Protocol (TCP)
                                 * socket will have no effect." but the MS runtime throws the
                                 * exception...) */
-                               if (protocol_type == ProtocolType.Tcp)
+                               if (protocolType == ProtocolType.Tcp)
                                        throw new SocketException ((int)SocketError.ProtocolOption);
 
-                               switch (address_family) {
+                               switch (addressFamily) {
                                case AddressFamily.InterNetwork:
                                        return ((int) GetSocketOption (SocketOptionLevel.IP, SocketOptionName.MulticastLoopback)) != 0;
                                case AddressFamily.InterNetworkV6:
@@ -440,10 +370,10 @@ namespace System.Net.Sockets
                                 * "Setting this property on a Transmission Control Protocol (TCP)
                                 * socket will have no effect." but the MS runtime throws the
                                 * exception...) */
-                               if (protocol_type == ProtocolType.Tcp)
+                               if (protocolType == ProtocolType.Tcp)
                                        throw new SocketException ((int)SocketError.ProtocolOption);
 
-                               switch (address_family) {
+                               switch (addressFamily) {
                                case AddressFamily.InterNetwork:
                                        SetSocketOption (SocketOptionLevel.IP, SocketOptionName.MulticastLoopback, value ? 1 : 0);
                                        break;
@@ -456,37 +386,6 @@ namespace System.Net.Sockets
                        }
                }
 
-               public bool DualMode {
-                       get {
-                               if (AddressFamily != AddressFamily.InterNetworkV6) 
-                                       throw new NotSupportedException("This protocol version is not supported");
-
-                               return ((int)GetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only) == 0);
-                       }
-                       set {
-                               if (AddressFamily != AddressFamily.InterNetworkV6) 
-                                       throw new NotSupportedException("This protocol version is not supported");
-
-                               SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, value ? 0 : 1);
-                       }
-               }
-
-               private bool IsDualMode {
-                       get {
-                               return AddressFamily == AddressFamily.InterNetworkV6 && DualMode;
-                       }
-               }
-
-               [MonoTODO ("This doesn't do anything on Mono yet")]
-               public bool UseOnlyOverlappedIO {
-                       get { return use_overlapped_io; }
-                       set { use_overlapped_io = value; }
-               }
-
-               public IntPtr Handle {
-                       get { return safe_handle.DangerousGetHandle (); }
-               }
-
                // Wish:  support non-IP endpoints.
                public EndPoint LocalEndPoint {
                        get {
@@ -498,7 +397,7 @@ namespace System.Net.Sockets
                                        return null;
 
                                int error;
-                               SocketAddress sa = LocalEndPoint_internal (safe_handle, (int) address_family, out error);
+                               SocketAddress sa = LocalEndPoint_internal (m_Handle, (int) addressFamily, out error);
 
                                if (error != 0)
                                        throw new SocketException (error);
@@ -523,61 +422,13 @@ namespace System.Net.Sockets
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                extern static SocketAddress LocalEndPoint_internal (IntPtr socket, int family, out int error);
 
-               public SocketType SocketType {
-                       get { return socket_type; }
-               }
-
-               public int SendTimeout {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               return (int) GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout);
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               if (value < -1)
-                                       throw new ArgumentOutOfRangeException ("value", "The value specified for a set operation is less than -1");
-
-                               /* According to the MSDN docs we should adjust values between 1 and
-                                * 499 to 500, but the MS runtime doesn't do this. */
-                               if (value == -1)
-                                       value = 0;
-
-                               SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, value);
-                       }
-               }
-
-               public int ReceiveTimeout {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               return (int) GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               if (value < -1)
-                                       throw new ArgumentOutOfRangeException ("value", "The value specified for a set operation is less than -1");
-
-                               if (value == -1)
-                                       value = 0;
-
-                               SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, value);
-                       }
-               }
-
-               public AddressFamily AddressFamily {
-                       get { return address_family; }
-               }
-
                public bool Blocking {
                        get { return is_blocking; }
                        set {
                                ThrowIfDisposedAndClosed ();
 
                                int error;
-                               Blocking_internal (safe_handle, value, out error);
+                               Blocking_internal (m_Handle, value, out error);
 
                                if (error != 0)
                                        throw new SocketException (error);
@@ -606,10 +457,7 @@ namespace System.Net.Sockets
                        internal set { is_connected = value; }
                }
 
-               public ProtocolType ProtocolType {
-                       get { return protocol_type; }
-               }
-
+               // FIXME: import from referencesource
                public bool NoDelay {
                        get {
                                ThrowIfDisposedAndClosed ();
@@ -625,70 +473,6 @@ namespace System.Net.Sockets
                        }
                }
 
-               public int ReceiveBufferSize {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               return (int) GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer);
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               if (value < 0)
-                                       throw new ArgumentOutOfRangeException ("value", "The value specified for a set operation is less than zero");
-
-                               SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, value);
-                       }
-               }
-
-               public int SendBufferSize {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               return (int) GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendBuffer);
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               if (value < 0)
-                                       throw new ArgumentOutOfRangeException ("value", "The value specified for a set operation is less than zero");
-
-                               SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendBuffer, value);
-                       }
-               }
-
-               public short Ttl {
-                       get {
-                               ThrowIfDisposedAndClosed ();
-
-                               switch (address_family) {
-                               case AddressFamily.InterNetwork:
-                                       return (short) (int) GetSocketOption (SocketOptionLevel.IP, SocketOptionName.IpTimeToLive);
-                               case AddressFamily.InterNetworkV6:
-                                       return (short) (int) GetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.HopLimit);
-                               default:
-                                       throw new NotSupportedException ("This property is only valid for InterNetwork and InterNetworkV6 sockets");
-                               }
-                       }
-                       set {
-                               ThrowIfDisposedAndClosed ();
-
-                               if (value < 0 || value > 255)
-                                       throw new ArgumentOutOfRangeException ("value", "The value specified for a set operation is less than zero or greater than 255.");
-
-                               switch (address_family) {
-                               case AddressFamily.InterNetwork:
-                                       SetSocketOption (SocketOptionLevel.IP, SocketOptionName.IpTimeToLive, value);
-                                       break;
-                               case AddressFamily.InterNetworkV6:
-                                       SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.HopLimit, value);
-                                       break;
-                               default:
-                                       throw new NotSupportedException ("This property is only valid for InterNetwork and InterNetworkV6 sockets");
-                               }
-                       }
-               }
-
                public EndPoint RemoteEndPoint {
                        get {
                                ThrowIfDisposedAndClosed ();
@@ -699,7 +483,7 @@ namespace System.Net.Sockets
                                        return null;
 
                                int error;
-                               SocketAddress sa = RemoteEndPoint_internal (safe_handle, (int) address_family, out error);
+                               SocketAddress sa = RemoteEndPoint_internal (m_Handle, (int) addressFamily, out error);
 
                                if (error != 0)
                                        throw new SocketException (error);
@@ -820,7 +604,7 @@ namespace System.Net.Sockets
                                throw new NotSupportedException ("'mode' parameter is not valid.");
 
                        int error;
-                       bool result = Poll_internal (safe_handle, mode, microSeconds, out error);
+                       bool result = Poll_internal (m_Handle, mode, microSeconds, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -859,7 +643,7 @@ namespace System.Net.Sockets
                        ThrowIfDisposedAndClosed ();
 
                        int error = 0;
-                       SafeSocketHandle safe_handle = Accept_internal (this.safe_handle, out error, is_blocking);
+                       SafeSocketHandle safe_handle = Accept_internal (this.m_Handle, out error, is_blocking);
 
                        if (error != 0) {
                                if (is_closed)
@@ -880,7 +664,7 @@ namespace System.Net.Sockets
                        ThrowIfDisposedAndClosed ();
 
                        int error = 0;
-                       SafeSocketHandle safe_handle = Accept_internal (this.safe_handle, out error, is_blocking);
+                       SafeSocketHandle safe_handle = Accept_internal (this.m_Handle, out error, is_blocking);
 
                        if (error != 0) {
                                if (is_closed)
@@ -888,10 +672,10 @@ namespace System.Net.Sockets
                                throw new SocketException (error);
                        }
 
-                       acceptSocket.address_family = this.AddressFamily;
-                       acceptSocket.socket_type = this.SocketType;
-                       acceptSocket.protocol_type = this.ProtocolType;
-                       acceptSocket.safe_handle = safe_handle;
+                       acceptSocket.addressFamily = this.AddressFamily;
+                       acceptSocket.socketType = this.SocketType;
+                       acceptSocket.protocolType = this.ProtocolType;
+                       acceptSocket.m_Handle = safe_handle;
                        acceptSocket.is_connected = true;
                        acceptSocket.seed_endpoint = this.seed_endpoint;
                        acceptSocket.Blocking = this.Blocking;
@@ -978,25 +762,6 @@ namespace System.Net.Sockets
                        sockares.Complete (acc_socket);
                });
 
-               public IAsyncResult BeginAccept (int receiveSize, AsyncCallback callback, object state)
-               {
-                       ThrowIfDisposedAndClosed ();
-
-                       if (receiveSize < 0)
-                               throw new ArgumentOutOfRangeException ("receiveSize", "receiveSize is less than zero");
-
-                       SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.AcceptReceive) {
-                               Buffer = new byte [receiveSize],
-                               Offset = 0,
-                               Size = receiveSize,
-                               SockFlags = SocketFlags.None,
-                       };
-
-                       QueueIOSelectorJob (readQ, sockares.Handle, new IOSelectorJob (IOOperation.Read, BeginAcceptReceiveCallback, sockares));
-
-                       return sockares;
-               }
-
                public IAsyncResult BeginAccept (Socket acceptSocket, int receiveSize, AsyncCallback callback, object state)
                {
                        ThrowIfDisposedAndClosed ();
@@ -1053,7 +818,7 @@ namespace System.Net.Sockets
                        if (sockares.Size > 0) {
                                try {
                                        SocketError error;
-                                       total = acc_socket.Receive_nochecks (sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out error);
+                                       total = acc_socket.Receive (sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out error);
                                        if (error != 0) {
                                                sockares.Complete (new SocketException ((int) error));
                                                return;
@@ -1074,12 +839,6 @@ namespace System.Net.Sockets
                        return EndAccept (out buffer, out bytes, result);
                }
 
-               public Socket EndAccept (out byte[] buffer, IAsyncResult asyncResult)
-               {
-                       int bytes;
-                       return EndAccept (out buffer, out bytes, asyncResult);
-               }
-
                public Socket EndAccept (out byte[] buffer, out int bytesTransferred, IAsyncResult asyncResult)
                {
                        ThrowIfDisposedAndClosed ();
@@ -1129,7 +888,7 @@ namespace System.Net.Sockets
                        }
                        
                        int error;
-                       Bind_internal (safe_handle, localEP.Serialize(), out error);
+                       Bind_internal (m_Handle, localEP.Serialize(), out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -1167,7 +926,7 @@ namespace System.Net.Sockets
                                throw new SocketException ((int) SocketError.InvalidArgument);
 
                        int error;
-                       Listen_internal(safe_handle, backlog, out error);
+                       Listen_internal(m_Handle, backlog, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -1222,7 +981,7 @@ namespace System.Net.Sockets
                                
                                iep = RemapIPEndPoint (iep);
 
-                               Connect_internal (safe_handle, iep.Serialize (), out error);
+                               Connect_internal (m_Handle, iep.Serialize (), out error);
                                if (error == 0) {
                                        is_connected = true;
                                        is_bound = true;
@@ -1258,7 +1017,7 @@ namespace System.Net.Sockets
 
                        IPEndPoint ep = remoteEP as IPEndPoint;
                        /* Dgram uses Any to 'disconnect' */
-                       if (ep != null && socket_type != SocketType.Dgram) {
+                       if (ep != null && socketType != SocketType.Dgram) {
                                if (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any))
                                        throw new SocketException ((int) SocketError.AddressNotAvailable);
                        }
@@ -1273,7 +1032,7 @@ namespace System.Net.Sockets
                        SocketAddress serial = remoteEP.Serialize ();
 
                        int error = 0;
-                       Connect_internal (safe_handle, serial, out error);
+                       Connect_internal (m_Handle, serial, out error);
 
                        if (error == 0 || error == 10035)
                                seed_endpoint = remoteEP; // Keep the ep around for non-blocking sockets
@@ -1284,7 +1043,7 @@ namespace System.Net.Sockets
                                throw new SocketException (error);
                        }
 
-                       is_connected = !(socket_type == SocketType.Dgram && ep != null && (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any)));
+                       is_connected = !(socketType == SocketType.Dgram && ep != null && (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any)));
                        is_bound = true;
                }
 
@@ -1359,29 +1118,13 @@ namespace System.Net.Sockets
                        }
                });
 
-               public IAsyncResult BeginConnect (IPAddress address, int port, AsyncCallback callback, object state)
-               {
-                       ThrowIfDisposedAndClosed ();
-
-                       if (address == null)
-                               throw new ArgumentNullException ("address");
-                       if (address.ToString ().Length == 0)
-                               throw new ArgumentException ("The length of the IP address is zero");
-                       if (port <= 0 || port > 65535)
-                               throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
-                       if (is_listening)
-                               throw new InvalidOperationException ();
-
-                       return BeginConnect (new IPEndPoint (address, port), callback, state);
-               }
-
                public IAsyncResult BeginConnect (string host, int port, AsyncCallback callback, object state)
                {
                        ThrowIfDisposedAndClosed ();
 
                        if (host == null)
                                throw new ArgumentNullException ("host");
-                       if (address_family != AddressFamily.InterNetwork && address_family != AddressFamily.InterNetworkV6)
+                       if (addressFamily != AddressFamily.InterNetwork && addressFamily != AddressFamily.InterNetworkV6)
                                throw new NotSupportedException ("This method is valid only for sockets in the InterNetwork and InterNetworkV6 families");
                        if (port <= 0 || port > 65535)
                                throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
@@ -1397,6 +1140,8 @@ namespace System.Net.Sockets
 
                        if (end_point == null)
                                throw new ArgumentNullException ("end_point");
+                       if (is_listening)
+                               throw new InvalidOperationException ();
 
                        SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.Connect) {
                                EndPoint = end_point,
@@ -1420,8 +1165,8 @@ namespace System.Net.Sockets
                                // Calling connect() again will reset the connection attempt and cause
                                // an error. Better to just close the socket and move on.
                                connect_in_progress = false;
-                               safe_handle.Dispose ();
-                               safe_handle = new SafeSocketHandle (Socket_internal (address_family, socket_type, protocol_type, out error), true);
+                               m_Handle.Dispose ();
+                               m_Handle = new SafeSocketHandle (Socket_internal (addressFamily, socketType, protocolType, out error), true);
                                if (error != 0)
                                        throw new SocketException (error);
                        }
@@ -1429,7 +1174,7 @@ namespace System.Net.Sockets
                        bool blk = is_blocking;
                        if (blk)
                                Blocking = false;
-                       Connect_internal (safe_handle, end_point.Serialize (), out error);
+                       Connect_internal (m_Handle, end_point.Serialize (), out error);
                        if (blk)
                                Blocking = true;
 
@@ -1624,7 +1369,7 @@ namespace System.Net.Sockets
                        ThrowIfDisposedAndClosed ();
 
                        int error = 0;
-                       Disconnect_internal (safe_handle, reuseSocket, out error);
+                       Disconnect_internal (m_Handle, reuseSocket, out error);
 
                        if (error != 0) {
                                if (error == 50) {
@@ -1728,97 +1473,26 @@ namespace System.Net.Sockets
 
 #region Receive
 
-               public int Receive (byte [] buffer)
-               {
-                       return Receive (buffer, SocketFlags.None);
-               }
-
-               public int Receive (byte [] buffer, SocketFlags socketFlags)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, 0, buffer.Length);
-
-                       SocketError error;
-                       int ret = Receive_nochecks (buffer, 0, buffer.Length, socketFlags, out error);
-
-                       if (error != SocketError.Success) {
-                               if (error == SocketError.WouldBlock && is_blocking) // This might happen when ReceiveTimeout is set
-                                       throw new SocketException ((int) error, TIMEOUT_EXCEPTION_MSG);
-                               throw new SocketException ((int) error);
-                       }
-
-                       return ret;
-               }
-
-               public int Receive (byte [] buffer, int size, SocketFlags socketFlags)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, 0, size);
-
-                       SocketError error;
-                       int ret = Receive_nochecks (buffer, 0, size, socketFlags, out error);
-
-                       if (error != SocketError.Success) {
-                               if (error == SocketError.WouldBlock && is_blocking) // This might happen when ReceiveTimeout is set
-                                       throw new SocketException ((int) error, TIMEOUT_EXCEPTION_MSG);
-                               throw new SocketException ((int) error);
-                       }
-
-                       return ret;
-               }
-
-               public int Receive (byte [] buffer, int offset, int size, SocketFlags socketFlags)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, offset, size);
-
-                       SocketError error;
-                       int ret = Receive_nochecks (buffer, offset, size, socketFlags, out error);
-
-                       if (error != SocketError.Success) {
-                               if (error == SocketError.WouldBlock && is_blocking) // This might happen when ReceiveTimeout is set
-                                       throw new SocketException ((int) error, TIMEOUT_EXCEPTION_MSG);
-                               throw new SocketException ((int) error);
-                       }
-
-                       return ret;
-               }
-
                public int Receive (byte [] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode)
                {
                        ThrowIfDisposedAndClosed ();
                        ThrowIfBufferNull (buffer);
                        ThrowIfBufferOutOfRange (buffer, offset, size);
 
-                       return Receive_nochecks (buffer, offset, size, socketFlags, out errorCode);
-               }
-
-               public int Receive (IList<ArraySegment<byte>> buffers)
-               {
-                       SocketError error;
-                       int ret = Receive (buffers, SocketFlags.None, out error);
+                       int nativeError;
+                       int ret = Receive_internal (m_Handle, buffer, offset, size, socketFlags, out nativeError);
 
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
+                       errorCode = (SocketError) nativeError;
+                       if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress) {
+                               is_connected = false;
+                               is_bound = false;
+                       } else {
+                               is_connected = true;
+                       }
 
                        return ret;
                }
 
-               [CLSCompliant (false)]
-               public int Receive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags)
-               {
-                       SocketError error;
-                       int ret = Receive (buffers, socketFlags, out error);
-
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return(ret);
-               }
-
                [CLSCompliant (false)]
                public int Receive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode)
                {
@@ -1849,7 +1523,7 @@ namespace System.Net.Sockets
                        }
 
                        try {
-                               ret = Receive_internal (safe_handle, bufarray, socketFlags, out nativeError);
+                               ret = Receive_internal (m_Handle, bufarray, socketFlags, out nativeError);
                        } finally {
                                for (int i = 0; i < numsegments; i++) {
                                        if (gch[i].IsAllocated)
@@ -1910,17 +1584,22 @@ namespace System.Net.Sockets
                        }
                });
 
-               public IAsyncResult BeginReceive (byte[] buffer, int offset, int size, SocketFlags socket_flags, AsyncCallback callback, object state)
+               public IAsyncResult BeginReceive (byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
                {
                        ThrowIfDisposedAndClosed ();
                        ThrowIfBufferNull (buffer);
                        ThrowIfBufferOutOfRange (buffer, offset, size);
 
+                       /* As far as I can tell from the docs and from experimentation, a pointer to the
+                        * SocketError parameter is not supposed to be saved for the async parts.  And as we don't
+                        * set any socket errors in the setup code, we just have to set it to Success. */
+                       errorCode = SocketError.Success;
+
                        SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.Receive) {
                                Buffer = buffer,
                                Offset = offset,
                                Size = size,
-                               SockFlags = socket_flags,
+                               SockFlags = socketFlags,
                        };
 
                        QueueIOSelectorJob (readQ, sockares.Handle, new IOSelectorJob (IOOperation.Read, BeginReceiveCallback, sockares));
@@ -1928,21 +1607,12 @@ namespace System.Net.Sockets
                        return sockares;
                }
 
-               public IAsyncResult BeginReceive (byte[] buffer, int offset, int size, SocketFlags flags, out SocketError error, AsyncCallback callback, object state)
-               {
-                       /* As far as I can tell from the docs and from experimentation, a pointer to the
-                        * SocketError parameter is not supposed to be saved for the async parts.  And as we don't
-                        * set any socket errors in the setup code, we just have to set it to Success. */
-                       error = SocketError.Success;
-                       return BeginReceive (buffer, offset, size, flags, callback, state);
-               }
-
                static IOAsyncCallback BeginReceiveCallback = new IOAsyncCallback (ares => {
                        SocketAsyncResult sockares = (SocketAsyncResult) ares;
                        int total = 0;
 
                        try {
-                               total = Receive_internal (sockares.socket.safe_handle, sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out sockares.error);
+                               total = Receive_internal (sockares.socket.m_Handle, sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out sockares.error);
                        } catch (Exception e) {
                                sockares.Complete (e);
                                return;
@@ -1952,13 +1622,16 @@ namespace System.Net.Sockets
                });
 
                [CLSCompliant (false)]
-               public IAsyncResult BeginReceive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
+               public IAsyncResult BeginReceive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
                {
                        ThrowIfDisposedAndClosed ();
 
                        if (buffers == null)
                                throw new ArgumentNullException ("buffers");
 
+                       /* I assume the same SocketError semantics as above */
+                       errorCode = SocketError.Success;
+
                        SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.ReceiveGeneric) {
                                Buffers = buffers,
                                SockFlags = socketFlags,
@@ -1969,14 +1642,6 @@ namespace System.Net.Sockets
                        return sockares;
                }
 
-               [CLSCompliant (false)]
-               public IAsyncResult BeginReceive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
-               {
-                       /* I assume the same SocketError semantics as above */
-                       errorCode = SocketError.Success;
-                       return BeginReceive (buffers, socketFlags, callback, state);
-               }
-
                static IOAsyncCallback BeginReceiveGenericCallback = new IOAsyncCallback (ares => {
                        SocketAsyncResult sockares = (SocketAsyncResult) ares;
                        int total = 0;
@@ -1991,20 +1656,6 @@ namespace System.Net.Sockets
                        sockares.Complete (total);
                });
 
-               public int EndReceive (IAsyncResult result)
-               {
-                       SocketError error;
-                       int bytesReceived = EndReceive (result, out error);
-
-                       if (error != SocketError.Success) {
-                               if (error != SocketError.WouldBlock && error != SocketError.InProgress)
-                                       is_connected = false;
-                               throw new SocketException ((int)error);
-                       }
-
-                       return bytesReceived;
-               }
-
                public int EndReceive (IAsyncResult asyncResult, out SocketError errorCode)
                {
                        ThrowIfDisposedAndClosed ();
@@ -2014,30 +1665,19 @@ namespace System.Net.Sockets
                        if (!sockares.IsCompleted)
                                sockares.AsyncWaitHandle.WaitOne ();
 
-                       // If no socket error occurred, call CheckIfThrowDelayedException in case there are other
+                       errorCode = sockares.ErrorCode;
+
+                       if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress)
+                               is_connected = false;
+
+                       // If no socket error occurred, call CheckIfThrowDelayedException in case there are other
                        // kinds of exceptions that should be thrown.
-                       if ((errorCode = sockares.ErrorCode) == SocketError.Success)
+                       if (errorCode == SocketError.Success)
                                sockares.CheckIfThrowDelayedException();
 
                        return sockares.Total;
                }
 
-               int Receive_nochecks (byte [] buf, int offset, int size, SocketFlags flags, out SocketError error)
-               {
-                       int nativeError;
-                       int ret = Receive_internal (safe_handle, buf, offset, size, flags, out nativeError);
-
-                       error = (SocketError) nativeError;
-                       if (error != SocketError.Success && error != SocketError.WouldBlock && error != SocketError.InProgress) {
-                               is_connected = false;
-                               is_bound = false;
-                       } else {
-                               is_connected = true;
-                       }
-
-                       return ret;
-               }
-
                static int Receive_internal (SafeSocketHandle safeHandle, WSABUF[] bufarray, SocketFlags flags, out int error)
                {
                        try {
@@ -2068,42 +1708,55 @@ namespace System.Net.Sockets
 
 #region ReceiveFrom
 
-               public int ReceiveFrom (byte [] buffer, ref EndPoint remoteEP)
+               public int ReceiveFrom (byte [] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP)
                {
                        ThrowIfDisposedAndClosed ();
                        ThrowIfBufferNull (buffer);
+                       ThrowIfBufferOutOfRange (buffer, offset, size);
 
-                       return ReceiveFrom (buffer, 0, buffer.Length, SocketFlags.None, ref remoteEP);
-               }
+                       if (remoteEP == null)
+                               throw new ArgumentNullException ("remoteEP");
 
-               public int ReceiveFrom (byte [] buffer, SocketFlags socketFlags, ref EndPoint remoteEP)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
+                       SocketError errorCode;
+                       int ret = ReceiveFrom (buffer, offset, size, socketFlags, ref remoteEP, out errorCode);
+
+                       if (errorCode != SocketError.Success)
+                               throw new SocketException (errorCode);
 
-                       return ReceiveFrom (buffer, 0, buffer.Length, socketFlags, ref remoteEP);
+                       return ret;
                }
 
-               public int ReceiveFrom (byte [] buffer, int size, SocketFlags socketFlags, ref EndPoint remoteEP)
+               internal int ReceiveFrom (byte [] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP, out SocketError errorCode)
                {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, 0, size);
+                       SocketAddress sockaddr = remoteEP.Serialize();
 
-                       return ReceiveFrom (buffer, 0, size, socketFlags, ref remoteEP);
-               }
+                       int nativeError;
+                       int cnt = ReceiveFrom_internal (m_Handle, buffer, offset, size, socketFlags, ref sockaddr, out nativeError);
 
-               public int ReceiveFrom (byte [] buffer, int offset, int size, SocketFlags socketFlags, ref EndPoint remoteEP)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, offset, size);
+                       errorCode = (SocketError) nativeError;
+                       if (errorCode != SocketError.Success) {
+                               if (errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress) {
+                                       is_connected = false;
+                               } else if (errorCode == SocketError.WouldBlock && is_blocking) { // This might happen when ReceiveTimeout is set
+                                       errorCode = SocketError.TimedOut;
+                               }
 
-                       if (remoteEP == null)
-                               throw new ArgumentNullException ("remoteEP");
+                               return 0;
+                       }
 
-                       int error;
-                       return ReceiveFrom_nochecks_exc (buffer, offset, size, socketFlags, ref remoteEP, true, out error);
+                       is_connected = true;
+                       is_bound = true;
+
+                       /* If sockaddr is null then we're a connection oriented protocol and should ignore the
+                        * remoteEP parameter (see MSDN documentation for Socket.ReceiveFrom(...) ) */
+                       if (sockaddr != null) {
+                               /* Stupidly, EndPoint.Create() is an instance method */
+                               remoteEP = remoteEP.Create (sockaddr);
+                       }
+
+                       seed_endpoint = remoteEP;
+
+                       return cnt;
                }
 
                public bool ReceiveFromAsync (SocketAsyncEventArgs e)
@@ -2173,8 +1826,13 @@ namespace System.Net.Sockets
                        int total = 0;
 
                        try {
-                               int error;
-                               total = sockares.socket.ReceiveFrom_nochecks_exc (sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, ref sockares.EndPoint, true, out error);
+                               SocketError errorCode;
+                               total = sockares.socket.ReceiveFrom (sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, ref sockares.EndPoint, out errorCode);
+
+                               if (errorCode != SocketError.Success) {
+                                       sockares.Complete (new SocketException (errorCode));
+                                       return;
+                               }
                        } catch (Exception e) {
                                sockares.Complete (e);
                                return;
@@ -2202,43 +1860,7 @@ namespace System.Net.Sockets
                        return sockares.Total;
                }
 
-               internal int ReceiveFrom_nochecks_exc (byte [] buf, int offset, int size, SocketFlags flags, ref EndPoint remote_end, bool throwOnError, out int error)
-               {
-                       SocketAddress sockaddr = remote_end.Serialize();
-
-                       int cnt = ReceiveFrom_internal (safe_handle, buf, offset, size, flags, ref sockaddr, out error);
-
-                       SocketError err = (SocketError) error;
-                       if (err != 0) {
-                               if (err != SocketError.WouldBlock && err != SocketError.InProgress) {
-                                       is_connected = false;
-                               } else if (err == SocketError.WouldBlock && is_blocking) { // This might happen when ReceiveTimeout is set
-                                       if (throwOnError)       
-                                               throw new SocketException ((int) SocketError.TimedOut, TIMEOUT_EXCEPTION_MSG);
-                                       error = (int) SocketError.TimedOut;
-                                       return 0;
-                               }
-
-                               if (throwOnError)
-                                       throw new SocketException (error);
-
-                               return 0;
-                       }
-
-                       is_connected = true;
-                       is_bound = true;
 
-                       /* If sockaddr is null then we're a connection oriented protocol and should ignore the
-                        * remote_end parameter (see MSDN documentation for Socket.ReceiveFrom(...) ) */
-                       if (sockaddr != null) {
-                               /* Stupidly, EndPoint.Create() is an instance method */
-                               remote_end = remote_end.Create (sockaddr);
-                       }
-
-                       seed_endpoint = remote_end;
-
-                       return cnt;
-               }
 
                static int ReceiveFrom_internal (SafeSocketHandle safeHandle, byte[] buffer, int offset, int count, SocketFlags flags, ref SocketAddress sockaddr, out int error)
                {
@@ -2309,115 +1931,35 @@ namespace System.Net.Sockets
 
 #endregion
 
-#region SetIPProtectionLevel
-
-               public void SetIPProtectionLevel (IPProtectionLevel level) {
-                       if (level == IPProtectionLevel.Unspecified)
-                               throw new ArgumentException (SR.GetString (SR.net_sockets_invalid_optionValue_all), "level");
-
-                       if (address_family == AddressFamily.InterNetworkV6)
-                               SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.IPProtectionLevel, (int)level);
-                       else if (address_family == AddressFamily.InterNetwork)
-                               SetSocketOption (SocketOptionLevel.IP, SocketOptionName.IPProtectionLevel, (int)level);
-                       else
-                               throw new NotSupportedException (SR.GetString (SR.net_invalidversion));
-               }
-
-#endregion
-
 #region Send
 
-               public int Send (byte [] buffer)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, 0, buffer.Length);
-
-                       SocketError error;
-                       int ret = Send_nochecks (buffer, 0, buffer.Length, SocketFlags.None, out error);
-
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return ret;
-               }
-
-               public int Send (byte [] buffer, SocketFlags socketFlags)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, 0, buffer.Length);
-
-                       SocketError error;
-                       int ret = Send_nochecks (buffer, 0, buffer.Length, socketFlags, out error);
-
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return ret;
-               }
-
-               public int Send (byte [] buffer, int size, SocketFlags socketFlags)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, 0, size);
-
-                       SocketError error;
-                       int ret = Send_nochecks (buffer, 0, size, socketFlags, out error);
-
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return ret;
-               }
-
-               public int Send (byte [] buffer, int offset, int size, SocketFlags socketFlags)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, offset, size);
-
-                       SocketError error;
-                       int ret = Send_nochecks (buffer, offset, size, socketFlags, out error);
-
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return ret;
-               }
-
                public int Send (byte [] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode)
                {
                        ThrowIfDisposedAndClosed ();
                        ThrowIfBufferNull (buffer);
                        ThrowIfBufferOutOfRange (buffer, offset, size);
 
-                       return Send_nochecks (buffer, offset, size, socketFlags, out errorCode);
-               }
-
-               public
-               int Send (IList<ArraySegment<byte>> buffers)
-               {
-                       SocketError error;
-                       int ret = Send (buffers, SocketFlags.None, out error);
-
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
-
-                       return ret;
-               }
-
-               public
-               int Send (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags)
-               {
-                       SocketError error;
-                       int ret = Send (buffers, socketFlags, out error);
+                       if (size == 0) {
+                               errorCode = SocketError.Success;
+                               return 0;
+                       }
 
-                       if (error != SocketError.Success)
-                               throw new SocketException ((int) error);
+                       int nativeError;
+                       int sent = 0;
+                       do {
+                               sent += Send_internal (
+m_Handle, buffer, offset + sent, size - sent, socketFlags, out nativeError);
+                               errorCode = (SocketError)nativeError;
+                               if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress) {
+                                       is_connected = false;
+                                       is_bound = false;
+                                       break;
+                               } else {
+                                       is_connected = true;
+                               }
+                       } while (sent < size);
 
-                       return ret;
+                       return sent;
                }
 
                [CLSCompliant (false)]
@@ -2449,7 +1991,7 @@ namespace System.Net.Sockets
                        }
 
                        try {
-                               ret = Send_internal (safe_handle, bufarray, socketFlags, out nativeError);
+                               ret = Send_internal (m_Handle, bufarray, socketFlags, out nativeError);
                        } finally {
                                for(int i = 0; i < numsegments; i++) {
                                        if (gch[i].IsAllocated) {
@@ -2463,30 +2005,6 @@ namespace System.Net.Sockets
                        return ret;
                }
 
-               int Send_nochecks (byte [] buf, int offset, int size, SocketFlags flags, out SocketError error)
-               {
-                       if (size == 0) {
-                               error = SocketError.Success;
-                               return 0;
-                       }
-
-                       int nativeError;
-                       int sent = 0;
-                       do {
-                               sent += Send_internal (safe_handle, buf, offset + sent, size - sent, flags, out nativeError);
-                               error = (SocketError)nativeError;
-                               if (error != SocketError.Success && error != SocketError.WouldBlock && error != SocketError.InProgress) {
-                                       is_connected = false;
-                                       is_bound = false;
-                                       break;
-                               } else {
-                                       is_connected = true;
-                               }
-                       } while (sent < size);
-
-                       return sent;
-               }
-
                public bool SendAsync (SocketAsyncEventArgs e)
                {
                        // NO check is made whether e != null in MS.NET (NRE is thrown in such case)
@@ -2534,29 +2052,22 @@ namespace System.Net.Sockets
 
                public IAsyncResult BeginSend (byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
                {
+                       ThrowIfDisposedAndClosed ();
+                       ThrowIfBufferNull (buffer);
+                       ThrowIfBufferOutOfRange (buffer, offset, size);
+
                        if (!is_connected) {
                                errorCode = SocketError.NotConnected;
-                               throw new SocketException ((int) errorCode);
+                               return null;
                        }
 
                        errorCode = SocketError.Success;
-                       return BeginSend (buffer, offset, size, socketFlags, callback, state);
-               }
-
-               public IAsyncResult BeginSend (byte[] buffer, int offset, int size, SocketFlags socket_flags, AsyncCallback callback, object state)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-                       ThrowIfBufferOutOfRange (buffer, offset, size);
-
-                       if (!is_connected)
-                               throw new SocketException ((int)SocketError.NotConnected);
 
                        SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.Send) {
                                Buffer = buffer,
                                Offset = offset,
                                Size = size,
-                               SockFlags = socket_flags,
+                               SockFlags = socketFlags,
                        };
 
                        QueueIOSelectorJob (writeQ, sockares.Handle, new IOSelectorJob (IOOperation.Write, s => BeginSendCallback ((SocketAsyncResult) s, 0), sockares));
@@ -2569,7 +2080,7 @@ namespace System.Net.Sockets
                        int total = 0;
 
                        try {
-                               total = Socket.Send_internal (sockares.socket.safe_handle, sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out sockares.error);
+                               total = Socket.Send_internal (sockares.socket.m_Handle, sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, out sockares.error);
                        } catch (Exception e) {
                                sockares.Complete (e);
                                return;
@@ -2580,7 +2091,7 @@ namespace System.Net.Sockets
                                sockares.Offset += total;
                                sockares.Size -= total;
 
-                               if (sockares.socket.is_disposed) {
+                               if (sockares.socket.CleanedUp) {
                                        sockares.Complete (total);
                                        return;
                                }
@@ -2596,14 +2107,20 @@ namespace System.Net.Sockets
                        sockares.Complete (total);
                }
 
-               public IAsyncResult BeginSend (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
+               [CLSCompliant (false)]
+               public IAsyncResult BeginSend (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
                {
                        ThrowIfDisposedAndClosed ();
 
                        if (buffers == null)
                                throw new ArgumentNullException ("buffers");
-                       if (!is_connected)
-                               throw new SocketException ((int)SocketError.NotConnected);
+
+                       if (!is_connected) {
+                               errorCode = SocketError.NotConnected;
+                               return null;
+                       }
+
+                       errorCode = SocketError.Success;
 
                        SocketAsyncResult sockares = new SocketAsyncResult (this, callback, state, SocketOperation.SendGeneric) {
                                Buffers = buffers,
@@ -2615,18 +2132,6 @@ namespace System.Net.Sockets
                        return sockares;
                }
 
-               [CLSCompliant (false)]
-               public IAsyncResult BeginSend (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
-               {
-                       if (!is_connected) {
-                               errorCode = SocketError.NotConnected;
-                               throw new SocketException ((int)errorCode);
-                       }
-
-                       errorCode = SocketError.Success;
-                       return BeginSend (buffers, socketFlags, callback, state);
-               }
-
                static IOAsyncCallback BeginSendGenericCallback = new IOAsyncCallback (ares => {
                        SocketAsyncResult sockares = (SocketAsyncResult) ares;
                        int total = 0;
@@ -2641,20 +2146,6 @@ namespace System.Net.Sockets
                        sockares.Complete (total);
                });
 
-               public int EndSend (IAsyncResult result)
-               {
-                       SocketError error;
-                       int bytesSent = EndSend (result, out error);
-
-                       if (error != SocketError.Success) {
-                               if (error != SocketError.WouldBlock && error != SocketError.InProgress)
-                                       is_connected = false;
-                               throw new SocketException ((int)error);
-                       }
-
-                       return bytesSent;
-               }
-
                public int EndSend (IAsyncResult asyncResult, out SocketError errorCode)
                {
                        ThrowIfDisposedAndClosed ();
@@ -2664,9 +2155,14 @@ namespace System.Net.Sockets
                        if (!sockares.IsCompleted)
                                sockares.AsyncWaitHandle.WaitOne ();
 
+                       errorCode = sockares.ErrorCode;
+
+                       if (errorCode != SocketError.Success && errorCode != SocketError.WouldBlock && errorCode != SocketError.InProgress)
+                               is_connected = false;
+
                        /* If no socket error occurred, call CheckIfThrowDelayedException in
                         * case there are other kinds of exceptions that should be thrown.*/
-                       if ((errorCode = sockares.ErrorCode) == SocketError.Success)
+                       if (errorCode == SocketError.Success)
                                sockares.CheckIfThrowDelayedException ();
 
                        return sockares.Total;
@@ -2704,27 +2200,6 @@ namespace System.Net.Sockets
 
 #region SendTo
 
-               public int SendTo (byte [] buffer, EndPoint remoteEP)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-
-                       return SendTo (buffer, 0, buffer.Length, SocketFlags.None, remoteEP);
-               }
-
-               public int SendTo (byte [] buffer, SocketFlags socketFlags, EndPoint remoteEP)
-               {
-                       ThrowIfDisposedAndClosed ();
-                       ThrowIfBufferNull (buffer);
-
-                       return SendTo (buffer, 0, buffer.Length, socketFlags, remoteEP);
-               }
-
-               public int SendTo (byte [] buffer, int size, SocketFlags socketFlags, EndPoint remoteEP)
-               {
-                       return SendTo (buffer, 0, size, socketFlags, remoteEP);
-               }
-
                public int SendTo (byte [] buffer, int offset, int size, SocketFlags socketFlags, EndPoint remoteEP)
                {
                        ThrowIfDisposedAndClosed ();
@@ -2734,7 +2209,21 @@ namespace System.Net.Sockets
                        if (remoteEP == null)
                                throw new ArgumentNullException("remoteEP");
 
-                       return SendTo_nochecks (buffer, offset, size, socketFlags, remoteEP);
+                       int error;
+                       int ret = SendTo_internal (m_Handle, buffer, offset, size, socketFlags, remoteEP.Serialize (), out error);
+
+                       SocketError err = (SocketError) error;
+                       if (err != 0) {
+                               if (err != SocketError.WouldBlock && err != SocketError.InProgress)
+                                       is_connected = false;
+                               throw new SocketException (error);
+                       }
+
+                       is_connected = true;
+                       is_bound = true;
+                       seed_endpoint = remoteEP;
+
+                       return ret;
                }
 
                public bool SendToAsync (SocketAsyncEventArgs e)
@@ -2801,7 +2290,7 @@ namespace System.Net.Sockets
                {
                        int total = 0;
                        try {
-                               total = sockares.socket.SendTo_nochecks (sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, sockares.EndPoint);
+                               total = sockares.socket.SendTo (sockares.Buffer, sockares.Offset, sockares.Size, sockares.SockFlags, sockares.EndPoint);
 
                                if (sockares.error == 0) {
                                        sent_so_far += total;
@@ -2837,25 +2326,6 @@ namespace System.Net.Sockets
                        return sockares.Total;
                }
 
-               int SendTo_nochecks (byte [] buffer, int offset, int size, SocketFlags flags, EndPoint remote_end)
-               {
-                       int error;
-                       int ret = SendTo_internal (safe_handle, buffer, offset, size, flags, remote_end.Serialize (), out error);
-
-                       SocketError err = (SocketError) error;
-                       if (err != 0) {
-                               if (err != SocketError.WouldBlock && err != SocketError.InProgress)
-                                       is_connected = false;
-                               throw new SocketException (error);
-                       }
-
-                       is_connected = true;
-                       is_bound = true;
-                       seed_endpoint = remote_end;
-
-                       return ret;
-               }
-
                static int SendTo_internal (SafeSocketHandle safeHandle, byte[] buffer, int offset, int count, SocketFlags flags, SocketAddress sa, out int error)
                {
                        try {
@@ -2873,18 +2343,6 @@ namespace System.Net.Sockets
 
 #region SendFile
 
-               public void SendFile (string fileName)
-               {
-                       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 ();
@@ -2894,7 +2352,7 @@ namespace System.Net.Sockets
                        if (!is_blocking)
                                throw new InvalidOperationException ();
 
-                       if (!SendFile_internal (safe_handle, fileName, preBuffer, postBuffer, flags)) {
+                       if (!SendFile_internal (m_Handle, fileName, preBuffer, postBuffer, flags)) {
                                SocketException exc = new SocketException ();
                                if (exc.ErrorCode == 2 || exc.ErrorCode == 3)
                                        throw new FileNotFoundException ();
@@ -2902,18 +2360,6 @@ namespace System.Net.Sockets
                        }
                }
 
-               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 ();
@@ -3018,10 +2464,10 @@ namespace System.Net.Sockets
                                (is_listening      ? SocketInformationOptions.Listening : 0) |
                                (is_connected      ? SocketInformationOptions.Connected : 0) |
                                (is_blocking       ? 0 : SocketInformationOptions.NonBlocking) |
-                               (use_overlapped_io ? SocketInformationOptions.UseOnlyOverlappedIO : 0);
+                               (useOverlappedIO ? SocketInformationOptions.UseOnlyOverlappedIO : 0);
 
-                       si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", (int)address_family, (int)socket_type, (int)protocol_type, is_bound ? 1 : 0, (long)Handle);
-                       safe_handle = null;
+                       si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", (int)addressFamily, (int)socketType, (int)protocolType, is_bound ? 1 : 0, (long)Handle);
+                       m_Handle = null;
 
                        return si;
                }
@@ -3038,7 +2484,7 @@ namespace System.Net.Sockets
                                throw new SocketException ((int) SocketError.Fault, "Error trying to dereference an invalid pointer");
 
                        int error;
-                       GetSocketOption_arr_internal (safe_handle, optionLevel, optionName, ref optionValue, out error);
+                       GetSocketOption_arr_internal (m_Handle, optionLevel, optionName, ref optionValue, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -3050,7 +2496,7 @@ namespace System.Net.Sockets
 
                        int error;
                        byte[] byte_val = new byte [optionLength];
-                       GetSocketOption_arr_internal (safe_handle, optionLevel, optionName, ref byte_val, out error);
+                       GetSocketOption_arr_internal (m_Handle, optionLevel, optionName, ref byte_val, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -3064,7 +2510,7 @@ namespace System.Net.Sockets
 
                        int error;
                        object obj_val;
-                       GetSocketOption_obj_internal (safe_handle, optionLevel, optionName, out obj_val, out error);
+                       GetSocketOption_obj_internal (m_Handle, optionLevel, optionName, out obj_val, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -3122,7 +2568,7 @@ namespace System.Net.Sockets
                                throw new SocketException ((int) SocketError.Fault, "Error trying to dereference an invalid pointer");
 
                        int error;
-                       SetSocketOption_internal (safe_handle, optionLevel, optionName, null, optionValue, 0, out error);
+                       SetSocketOption_internal (m_Handle, optionLevel, optionName, null, optionValue, 0, out error);
 
                        if (error != 0) {
                                if (error == (int) SocketError.InvalidArgument)
@@ -3145,17 +2591,17 @@ namespace System.Net.Sockets
                                LingerOption linger = optionValue as LingerOption;
                                if (linger == null)
                                        throw new ArgumentException ("A 'LingerOption' value must be specified.", "optionValue");
-                               SetSocketOption_internal (safe_handle, optionLevel, optionName, linger, null, 0, out error);
+                               SetSocketOption_internal (m_Handle, optionLevel, optionName, linger, null, 0, out error);
                        } else if (optionLevel == SocketOptionLevel.IP && (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)) {
                                MulticastOption multicast = optionValue as MulticastOption;
                                if (multicast == null)
                                        throw new ArgumentException ("A 'MulticastOption' value must be specified.", "optionValue");
-                               SetSocketOption_internal (safe_handle, optionLevel, optionName, multicast, null, 0, out error);
+                               SetSocketOption_internal (m_Handle, optionLevel, optionName, multicast, null, 0, out error);
                        } else if (optionLevel == SocketOptionLevel.IPv6 && (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)) {
                                IPv6MulticastOption multicast = optionValue as IPv6MulticastOption;
                                if (multicast == null)
                                        throw new ArgumentException ("A 'IPv6MulticastOption' value must be specified.", "optionValue");
-                               SetSocketOption_internal (safe_handle, optionLevel, optionName, multicast, null, 0, out error);
+                               SetSocketOption_internal (m_Handle, optionLevel, optionName, multicast, null, 0, out error);
                        } else {
                                throw new ArgumentException ("Invalid value specified.", "optionValue");
                        }
@@ -3178,11 +2624,11 @@ namespace System.Net.Sockets
                {
                        ThrowIfDisposedAndClosed ();
 
-                       if (optionLevel == SocketOptionLevel.Socket && optionName == SocketOptionName.ReuseAddress && optionValue != 0 && !SupportsPortReuse (protocol_type))
+                       if (optionLevel == SocketOptionLevel.Socket && optionName == SocketOptionName.ReuseAddress && optionValue != 0 && !SupportsPortReuse (protocolType))
                                throw new SocketException ((int) SocketError.OperationNotSupported, "Operating system sockets do not support ReuseAddress.\nIf your socket is not intended to bind to the same address and port multiple times remove this option, otherwise you should ignore this exception inside a try catch and check that ReuseAddress is true before binding to the same address and port multiple times.");
 
                        int error;
-                       SetSocketOption_internal (safe_handle, optionLevel, optionName, null, null, optionValue, out error);
+                       SetSocketOption_internal (m_Handle, optionLevel, optionName, null, null, optionValue, out error);
 
                        if (error != 0) {
                                if (error == (int) SocketError.InvalidArgument)
@@ -3212,11 +2658,11 @@ namespace System.Net.Sockets
 
                public int IOControl (int ioControlCode, byte [] optionInValue, byte [] optionOutValue)
                {
-                       if (is_disposed)
+                       if (CleanedUp)
                                throw new ObjectDisposedException (GetType ().ToString ());
 
                        int error;
-                       int result = IOControl_internal (safe_handle, ioControlCode, optionInValue, optionOutValue, out error);
+                       int result = IOControl_internal (m_Handle, ioControlCode, optionInValue, optionOutValue, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -3226,11 +2672,6 @@ namespace System.Net.Sockets
                        return result;
                }
 
-               public int IOControl (IOControlCode ioControlCode, byte[] optionInValue, byte[] optionOutValue)
-               {
-                       return IOControl ((int) ioControlCode, optionInValue, optionOutValue);
-               }
-
                static int IOControl_internal (SafeSocketHandle safeHandle, int ioctl_code, byte [] input, byte [] output, out int error)
                {
                        bool release = false;
@@ -3280,7 +2721,7 @@ namespace System.Net.Sockets
                                throw new SocketException (10057); // Not connected
 
                        int error;
-                       Shutdown_internal (safe_handle, how, out error);
+                       Shutdown_internal (m_Handle, how, out error);
 
                        if (error != 0)
                                throw new SocketException (error);
@@ -3307,30 +2748,24 @@ namespace System.Net.Sockets
 
                protected virtual void Dispose (bool disposing)
                {
-                       if (is_disposed)
+                       if (CleanedUp)
                                return;
 
-                       is_disposed = true;
+                       m_IntCleanedUp = 1;
                        bool was_connected = is_connected;
                        is_connected = false;
 
-                       if (safe_handle != null) {
+                       if (m_Handle != null) {
                                is_closed = true;
                                IntPtr x = Handle;
 
                                if (was_connected)
                                        Linger (x);
 
-                               safe_handle.Dispose ();
+                               m_Handle.Dispose ();
                        }
                }
 
-               public void Dispose ()
-               {
-                       Dispose (true);
-                       GC.SuppressFinalize (this);
-               }
-
                void Linger (IntPtr handle)
                {
                        if (!is_connected || linger_timeout <= 0)
@@ -3365,13 +2800,13 @@ namespace System.Net.Sockets
 
                void ThrowIfDisposedAndClosed (Socket socket)
                {
-                       if (socket.is_disposed && socket.is_closed)
+                       if (socket.CleanedUp && socket.is_closed)
                                throw new ObjectDisposedException (socket.GetType ().ToString ());
                }
 
                void ThrowIfDisposedAndClosed ()
                {
-                       if (is_disposed && is_closed)
+                       if (CleanedUp && is_closed)
                                throw new ObjectDisposedException (GetType ().ToString ());
                }
 
@@ -3395,7 +2830,7 @@ namespace System.Net.Sockets
 
                void ThrowIfUdp ()
                {
-                       if (protocol_type == ProtocolType.Udp)
+                       if (protocolType == ProtocolType.Udp)
                                throw new SocketException ((int)SocketError.ProtocolOption);
                }
 
index 980ad06e5b2f909333222afba5fea6ea9da6ead2..b0e806cccd35e368b4755d95e505599d014f2912 100644 (file)
@@ -140,7 +140,7 @@ namespace System.Net.Sockets
 
                public void Complete ()
                {
-                       if (operation != SocketOperation.Receive && socket.is_disposed)
+                       if (operation != SocketOperation.Receive && socket.CleanedUp)
                                DelayedException = new ObjectDisposedException (socket.GetType ().ToString ());
 
                        IsCompleted = true;
@@ -173,7 +173,7 @@ namespace System.Net.Sockets
                                        if (queue.Count > 0)
                                                queue.Dequeue (); /* remove ourselves */
                                        if (queue.Count > 0) {
-                                               if (!socket.is_disposed) {
+                                               if (!socket.CleanedUp) {
                                                        IOSelector.Add (queue.Peek ().Key, queue.Peek ().Value);
                                                } else {
                                                        /* CompleteAllOnDispose */
index 802bfabc21a919416ea4e7f2502c6563143cb22b..17c1b6950926695eecb48299ecd7c8f5dac48007 100644 (file)
@@ -387,6 +387,7 @@ System.Net.Sockets/SafeSocketHandle.cs
 ../referencesource/System/net/System/Net/Sockets/SelectMode.cs
 System.Net.Sockets/SendPacketsElement.cs
 System.Net.Sockets/Socket.cs
+../referencesource/System/net/System/Net/Sockets/Socket.cs
 System.Net.Sockets/SocketAsyncEventArgs.cs
 System.Net.Sockets/SocketAsyncOperation.cs
 System.Net.Sockets/SocketAsyncResult.cs
index 3245ecf53e980510d2c7ab7919fc727a03520191..7f99dfb96bf5c50664c0940e59a9087dfffd4f9d 100644 (file)
@@ -131,6 +131,7 @@ System.Net.Sockets/SafeSocketHandle.cs
 ../referencesource/System/net/System/Net/Sockets/SelectMode.cs
 System.Net.Sockets/SendPacketsElement.cs
 System.Net.Sockets/Socket.cs
+../referencesource/System/net/System/Net/Sockets/Socket.cs
 System.Net.Sockets/SocketAsyncEventArgs.cs
 System.Net.Sockets/SocketAsyncOperation.cs
 System.Net.Sockets/SocketAsyncResult.cs
index 1d92faa541f6a2d6c5a5700a11dc0113895d3e89..506c90a59d6cb5cdf050ab20aa639faf9fb7737e 100644 (file)
@@ -4,6 +4,10 @@
 // </copyright>
 //------------------------------------------------------------------------------
 
+#if MONO
+#undef FEATURE_PAL
+#endif
+
 namespace System.Net.Sockets {
     using System.Collections;
     using System.Collections.Generic;
@@ -24,9 +28,9 @@ namespace System.Net.Sockets {
     ///    interface.</para>
     /// </devdoc>
 
-
-    public class Socket : IDisposable
+    public partial class Socket : IDisposable
     {
+#if !MONO
         internal const int DefaultCloseTimeout = -1; // don't change for default, otherwise breaking change
 
         // AcceptQueue - queued list of accept requests for BeginAccept or async Result for Begin Connect
@@ -81,12 +85,12 @@ namespace System.Net.Sockets {
         //
         // Overlapped constants.
         //
-#if !FEATURE_PAL || CORIOLIS
+#if !(FEATURE_PAL && !MONO) || CORIOLIS
         internal static volatile bool UseOverlappedIO;
 #else
         // Disable the I/O completion port for Rotor
         internal static volatile bool UseOverlappedIO = true;
-#endif // !FEATURE_PAL || CORIOLIS
+#endif // !(FEATURE_PAL && !MONO) || CORIOLIS
         private bool useOverlappedIO;
 
         // Bool marked true if the native socket m_Handle was bound to the ThreadPool
@@ -120,6 +124,7 @@ namespace System.Net.Sockets {
 #if !FEATURE_PAL // perfcounter
         internal static volatile bool s_PerfCountersEnabled;
 #endif
+#endif // !MONO
 
 //************* constructors *************************
 
@@ -131,6 +136,7 @@ namespace System.Net.Sockets {
             DualMode = true;
         }
 
+#if !MONO
         /// <devdoc>
         ///    <para>
         ///       Initializes a new instance of the <see cref='Sockets.Socket'/> class.
@@ -475,6 +481,7 @@ namespace System.Net.Sockets {
                 return m_RemoteEndPoint;
             }
         }
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>
@@ -484,10 +491,13 @@ namespace System.Net.Sockets {
         /// </devdoc>
         public IntPtr Handle {
             get {
+#if !MONO
                 ExceptionHelper.UnmanagedPermission.Demand();
+#endif
                 return m_Handle.DangerousGetHandle();
             }
         }
+#if !MONO
         internal SafeCloseSocket SafeHandle {
             get {
                 return m_Handle;
@@ -534,6 +544,7 @@ namespace System.Net.Sockets {
                 willBlock = current;
             }
         }
+#endif // !MONO
 
         public bool UseOnlyOverlappedIO{
             get {
@@ -544,16 +555,17 @@ namespace System.Net.Sockets {
 
             }
             set {
-
+#if !MONO
                 if (m_BoundToThreadPool) {
                     throw new InvalidOperationException(SR.GetString(SR.net_io_completionportwasbound));
                 }
+#endif
 
                 useOverlappedIO = value;
             }
         }
 
-
+#if !MONO
         /// <devdoc>
         ///    <para>
         ///       Gets the connection state of the Socket. This property will return the latest
@@ -577,6 +589,7 @@ namespace System.Net.Sockets {
                 return m_IsConnected;
             }
         }
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>
@@ -611,13 +624,13 @@ namespace System.Net.Sockets {
             }
         }
 
-
+#if !MONO
         public bool IsBound{
             get{
                 return (m_RightEndPoint != null);
             }
         }
-
+#endif // !MONO
 
         public bool ExclusiveAddressUse{
             get {
@@ -707,6 +720,7 @@ namespace System.Net.Sockets {
             }
         }
 
+#if !MONO
         public bool NoDelay {
             get {
                 return (int)GetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay) != 0 ? true : false;
@@ -715,6 +729,7 @@ namespace System.Net.Sockets {
                 SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, value ? 1 : 0);
             }
         }
+#endif // !MONO
 
         public short Ttl{
             get {
@@ -769,6 +784,7 @@ namespace System.Net.Sockets {
             }
         }
 
+#if !MONO
         public bool MulticastLoopback{
             get {
                 if (addressFamily == AddressFamily.InterNetwork) {
@@ -796,7 +812,6 @@ namespace System.Net.Sockets {
             }
         }
 
-
         public bool EnableBroadcast{
             get {
                 return (int)GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast) != 0 ? true : false;
@@ -805,7 +820,8 @@ namespace System.Net.Sockets {
                 SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, value ? 1 : 0);
             }
         }
-                
+#endif // !MONO
+
         public bool DualMode {
             get {
                 if (AddressFamily != AddressFamily.InterNetworkV6) {
@@ -837,7 +853,7 @@ namespace System.Net.Sockets {
 
 
 
-
+#if !MONO
         /// <devdoc>
         ///    <para>Associates a socket with an end point.</para>
         /// </devdoc>
@@ -1258,7 +1274,7 @@ namespace System.Net.Sockets {
             }
             return socket;
         }
-
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>Sends a data buffer to a connected socket.</para>
@@ -1300,7 +1316,7 @@ namespace System.Net.Sockets {
             return bytesTransferred;
         }
 
-
+#if !MONO
         public int Send(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode) {
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Send", "");
             if (CleanedUp) {
@@ -1392,8 +1408,7 @@ namespace System.Net.Sockets {
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Send", bytesTransferred);
             return bytesTransferred;
         }
-
-
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>Sends a file to
@@ -1406,8 +1421,7 @@ namespace System.Net.Sockets {
             SendFile(fileName,null,null,TransmitFileOptions.UseDefaultWorkerThread);
         }
 
-
-
+#if !MONO
         /// <devdoc>
         ///    <para>Sends a file to
         ///       a connected socket.</para>
@@ -1492,6 +1506,7 @@ namespace System.Net.Sockets {
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "SendFile", errorCode);
             return;
         }
+#endif // !MONO
 #endif // !FEATURE_PAL
 
 
@@ -1511,8 +1526,7 @@ namespace System.Net.Sockets {
             return bytesTransferred;
         }
 
-
-
+#if !MONO
         public int Send(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode) {
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Send", "");
 
@@ -1688,6 +1702,7 @@ namespace System.Net.Sockets {
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "SendTo", bytesTransferred);
             return bytesTransferred;
         }
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>Sends data to a specific end point, starting at the indicated location in the data.</para>
@@ -1695,12 +1710,14 @@ namespace System.Net.Sockets {
         public int SendTo(byte[] buffer, int size, SocketFlags socketFlags, EndPoint remoteEP) {
             return SendTo(buffer, 0, size, socketFlags, remoteEP);
         }
+
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
         /// </devdoc>
         public int SendTo(byte[] buffer, SocketFlags socketFlags, EndPoint remoteEP) {
             return SendTo(buffer, 0, buffer!=null ? buffer.Length : 0, socketFlags, remoteEP);
         }
+
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
         /// </devdoc>
@@ -1742,7 +1759,7 @@ namespace System.Net.Sockets {
             return bytesTransferred;
         }
 
-
+#if !MONO
         public int Receive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode) {
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Receive", "");
             if (CleanedUp) {
@@ -1820,7 +1837,7 @@ namespace System.Net.Sockets {
 
             return bytesTransferred;
         }
-
+#endif // !MONO
 
         public int Receive(IList<ArraySegment<byte>> buffers) {
             return Receive(buffers,SocketFlags.None);
@@ -1836,6 +1853,7 @@ namespace System.Net.Sockets {
             return bytesTransferred;
         }
 
+#if !MONO
         public int Receive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode) {
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Receive", "");
             if (CleanedUp) {
@@ -2153,8 +2171,7 @@ namespace System.Net.Sockets {
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "ReceiveFrom", bytesTransferred);
             return bytesTransferred;
         }
-
-
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>Receives a datagram and stores the source end point.</para>
@@ -2175,6 +2192,7 @@ namespace System.Net.Sockets {
             return ReceiveFrom(buffer, 0, buffer!=null ? buffer.Length : 0, SocketFlags.None, ref remoteEP);
         }
 
+#if !MONO
         // UE
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
@@ -2220,6 +2238,7 @@ namespace System.Net.Sockets {
 
             return realOptionLength;
         }
+#endif // !MONO
 
         // UE
         /// <devdoc>
@@ -2229,6 +2248,7 @@ namespace System.Net.Sockets {
             return IOControl(unchecked((int)ioControlCode),optionInValue,optionOutValue);
         }
 
+#if !MONO
         internal int IOControl(        IOControlCode ioControlCode, 
                                                                        IntPtr optionInValue, 
                                                                        int inValueSize,
@@ -2273,6 +2293,7 @@ namespace System.Net.Sockets {
 
             return realOptionLength;
         }
+#endif // !MONO
 
         public void SetIPProtectionLevel(IPProtectionLevel level) {
             if (level == IPProtectionLevel.Unspecified) {
@@ -2290,6 +2311,7 @@ namespace System.Net.Sockets {
             }
         }
 
+#if !MONO
         /// <devdoc>
         ///    <para>
         ///       Sets the specified option to the specified value.
@@ -2660,6 +2682,7 @@ namespace System.Net.Sockets {
             SelectFileDescriptor(checkWrite, writefileDescriptorSet);
             SelectFileDescriptor(checkError, errfileDescriptorSet);
         }
+#endif // !MONO
 
 #if !FEATURE_PAL
         /// <devdoc>
@@ -2678,7 +2701,7 @@ namespace System.Net.Sockets {
         }
 #endif
 
-
+#if !MONO
         //
         // Async Winsock Support, the following functions use either
         //   the Async Winsock support to do overlapped I/O WSASend/WSARecv
@@ -3100,6 +3123,7 @@ namespace System.Net.Sockets {
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "BeginConnect", result);
             return result;
         }
+#endif // !MONO
 
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginConnect(IPAddress address, int port, AsyncCallback requestCallback, object state){
@@ -3124,6 +3148,7 @@ namespace System.Net.Sockets {
             return result;
         }
 
+#if !MONO
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginConnect(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state)
         {
@@ -3193,7 +3218,7 @@ namespace System.Net.Sockets {
 
             GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginDisconnect() ");
 
-#if FEATURE_PAL
+#if FEATURE_PAL && !MONO
             throw new PlatformNotSupportedException(SR.GetString(SR.WinXPRequired));
 #endif
 
@@ -3242,9 +3267,9 @@ namespace System.Net.Sockets {
                  throw new ObjectDisposedException(this.GetType().FullName);
              }
 
-#if FEATURE_PAL
+#if FEATURE_PAL && !MONO
             throw new PlatformNotSupportedException(SR.GetString(SR.WinXPRequired));
-#endif // FEATURE_PAL
+#endif // FEATURE_PAL && !MONO
 
 
              GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::Disconnect() ");
@@ -3370,9 +3395,9 @@ namespace System.Net.Sockets {
                throw new ObjectDisposedException(this.GetType().FullName);
              }
 
-#if FEATURE_PAL
+#if FEATURE_PAL && !MONO
             throw new PlatformNotSupportedException(SR.GetString(SR.WinNTRequired));
-#endif // FEATURE_PAL
+#endif // FEATURE_PAL && !MONO
 
              if (asyncResult==null) {
                throw new ArgumentNullException("asyncResult");
@@ -3412,7 +3437,7 @@ namespace System.Net.Sockets {
              if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "EndDisconnect", null);
              return;
         }
-
+#endif // !MONO
 
         /*++
 
@@ -3451,6 +3476,7 @@ namespace System.Net.Sockets {
             return result;
         }
 
+#if !MONO
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
         {
@@ -3620,9 +3646,9 @@ namespace System.Net.Sockets {
                 throw new ObjectDisposedException(this.GetType().FullName);
             }
 
-#if FEATURE_PAL
+#if FEATURE_PAL && !MONO
             throw new PlatformNotSupportedException(SR.GetString(SR.WinNTRequired));
-#endif // FEATURE_PAL
+#endif // FEATURE_PAL && !MONO
 
 
             if (!Connected) {
@@ -3698,7 +3724,7 @@ namespace System.Net.Sockets {
         }
 
 #endif // !FEATURE_PAL
-
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
@@ -3714,7 +3740,7 @@ namespace System.Net.Sockets {
             return result;
         }
 
-
+#if !MONO
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginSend(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
         {
@@ -3804,7 +3830,7 @@ namespace System.Net.Sockets {
             }
             return errorCode;
         }
-
+#endif // !MONO
 
         /*++
 
@@ -3836,7 +3862,7 @@ namespace System.Net.Sockets {
             return bytesTransferred;
         }
 
-
+#if !MONO
         public int EndSend(IAsyncResult asyncResult, out SocketError errorCode) {
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "EndSend", asyncResult);
             if (CleanedUp) {
@@ -3904,9 +3930,9 @@ namespace System.Net.Sockets {
                 throw new ObjectDisposedException(this.GetType().FullName);
             }
 
-#if FEATURE_PAL
+#if FEATURE_PAL && !MONO
             throw new PlatformNotSupportedException(SR.GetString(SR.WinNTRequired));
-#endif // FEATURE_PAL
+#endif // FEATURE_PAL && !MONO
             //
             // parameter validation
             //
@@ -4160,7 +4186,7 @@ namespace System.Net.Sockets {
             if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "EndSendTo", bytesTransferred);
             return bytesTransferred;
         }
-
+#endif // !MONO
 
         /*++
 
@@ -4206,6 +4232,7 @@ namespace System.Net.Sockets {
         }
 
 
+#if !MONO
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
         {
@@ -4329,7 +4356,7 @@ namespace System.Net.Sockets {
 
             return errorCode;
         }
-
+#endif // !MONO
 
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
@@ -4342,7 +4369,7 @@ namespace System.Net.Sockets {
             return result;
         }
 
-
+#if !MONO
         [HostProtection(ExternalThreading=true)]
         public IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state)
         {
@@ -4451,6 +4478,8 @@ namespace System.Net.Sockets {
         private int m_LastReceiveTick;
 #endif
 
+#endif // !MONO
+
         /*++
 
         Routine Description:
@@ -4481,7 +4510,7 @@ namespace System.Net.Sockets {
             return bytesTransferred;
         }
 
-
+#if !MONO
         public int EndReceive(IAsyncResult asyncResult, out SocketError errorCode) {
             if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "EndReceive", asyncResult);
             if (CleanedUp) {
@@ -5342,8 +5371,10 @@ namespace System.Net.Sockets {
                 }
             }
         }
+#endif // !MONO
 
 #if !FEATURE_PAL
+#if !MONO
         private bool CanUseAcceptEx
         {
             get
@@ -5352,6 +5383,7 @@ namespace System.Net.Sockets {
                     (Thread.CurrentThread.IsThreadPoolThread || SettingsSectionInternal.Section.AlwaysUseCompletionPortsForAccept || m_IsDisconnected);
             }
         }
+#endif // !MONO
 
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
@@ -5363,6 +5395,7 @@ namespace System.Net.Sockets {
 
         ///  This is the true async version that uses AcceptEx
 
+#if !MONO
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
         /// </devdoc>
@@ -5461,10 +5494,9 @@ namespace System.Net.Sockets {
                 throw socketException;
             }
         }
-
+#endif // !MONO
 #endif // !FEATURE_PAL
 
-
         /*++
 
         Routine Description:
@@ -5483,6 +5515,7 @@ namespace System.Net.Sockets {
 
         --*/
 
+#if !MONO
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
         /// </devdoc>
@@ -5552,9 +5585,9 @@ namespace System.Net.Sockets {
             }
             return acceptedSocket;
         }
+#endif // !MONO
 
 #if !FEATURE_PAL
-
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
         /// </devdoc>
@@ -5569,6 +5602,7 @@ namespace System.Net.Sockets {
             return socket;
         }
 
+#if !MONO
         /// <devdoc>
         ///    <para>[To be supplied.]</para>
         /// </devdoc>
@@ -5635,13 +5669,13 @@ namespace System.Net.Sockets {
             }
             return socket;
         }
-
+#endif // !MONO
 #endif // !FEATURE_PAL
 
 
 
 
-
+#if !MONO
         /// <devdoc>
         ///    <para>
         ///       Disables sends and receives on a socket.
@@ -5821,6 +5855,7 @@ namespace System.Net.Sockets {
                 Interlocked.CompareExchange(ref m_AcceptQueueOrConnectResult, new Queue(16), null);
             return (Queue)m_AcceptQueueOrConnectResult;
         }
+#endif // !MONO
 
         internal bool CleanedUp {
             get {
@@ -5828,6 +5863,7 @@ namespace System.Net.Sockets {
             }
         }
 
+#if !MONO
         internal TransportType Transport {
             get {
                 return
@@ -6330,6 +6366,7 @@ namespace System.Net.Sockets {
                 m_AsyncEvent.Close();
             }
         }
+#endif // !MONO
 
         public void Dispose() {
             Dispose(true);
@@ -6340,6 +6377,7 @@ namespace System.Net.Sockets {
             Dispose(false);
         }
 
+#if !MONO
         // this version does not throw.
         internal void InternalShutdown(SocketShutdown how) {
             GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::InternalShutdown() how:" + how.ToString());
@@ -8350,10 +8388,10 @@ namespace System.Net.Sockets {
 
             return retval;
         }
-
+#endif // !MONO
     }  // end of class Socket
 
-
+#if !MONO
     internal class ConnectAsyncResult:ContextAwareResult{
         private EndPoint m_EndPoint;
         internal ConnectAsyncResult(object myObject, EndPoint endPoint, object myState, AsyncCallback myCallBack):base(myObject, myState, myCallBack) {
@@ -10234,5 +10272,6 @@ namespace System.Net.Sockets {
         }
     }
 #endif // SOCKETTHREADPOOL
+#endif // !MONO
 
 }
index d4d168da76691a76c3f041b40cf2c45dde95d775..b4a85f27fa4f6d899ad1f40a3e895e9eaabef393 100644 (file)
@@ -1787,7 +1787,7 @@ Socket_to_SOCKET (MonoObject *sockobj)
        MonoSafeHandle *safe_handle;
        MonoClassField *field;
        
-       field = mono_class_get_field_from_name (sockobj->vtable->klass, "safe_handle");
+       field = mono_class_get_field_from_name (sockobj->vtable->klass, "m_Handle");
        safe_handle = ((MonoSafeHandle *)(*(gpointer *)(((char *)sockobj) + field->offset)));
 
        if (safe_handle == NULL)