New tests.
[mono.git] / mcs / class / System / System.Net.Sockets / Socket_2_1.cs
index d9040122426efeaaf4b64b929eb82dea7f50a832..af54044c3d50f2039abc56e331ebfc96c0462583 100644 (file)
@@ -227,7 +227,7 @@ namespace System.Net.Sockets {
                                                             bool block,
                                                             out int error);
 #endif
-#if !NET_2_1 || MONOTOUCH
+
                public bool Blocking {
                        get {
                                return(blocking);
@@ -246,7 +246,7 @@ namespace System.Net.Sockets {
                                blocking=value;
                        }
                }
-#endif
+
                public bool Connected {
                        get { return connected; }
                        internal set { connected = value; }
@@ -384,7 +384,7 @@ namespace System.Net.Sockets {
 
                void Linger (IntPtr handle)
                {
-                       if (linger_timeout <= 0)
+                       if (!connected || linger_timeout <= 0)
                                return;
 
                        // We don't want to receive any more data
@@ -417,6 +417,7 @@ namespace System.Net.Sockets {
                                return;
 
                        disposed = true;
+                       bool was_connected = connected;
                        connected = false;
                        if ((int) socket != -1) {
                                int error;
@@ -429,7 +430,8 @@ namespace System.Net.Sockets {
                                        blocking_thread = null;
                                }
 
-                               Linger (x);
+                               if (was_connected)
+                                       Linger (x);
                                //DateTime start = DateTime.UtcNow;
                                Close_internal (x, out error);
                                //Console.WriteLine ("Time spent in Close_internal: {0}ms", (DateTime.UtcNow - start).TotalMilliseconds);
@@ -487,7 +489,7 @@ namespace System.Net.Sockets {
                                if (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any))
                                        throw new SocketException ((int) SocketError.AddressNotAvailable);
 
-#if NET_2_1 && !MONOTOUCH
+#if MOONLIGHT
                        if (protocol_type != ProtocolType.Tcp)
                                throw new SocketException ((int) SocketError.AccessDenied);
 #elif NET_2_0
@@ -563,7 +565,6 @@ namespace System.Net.Sockets {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                extern static bool Poll_internal (IntPtr socket, SelectMode mode, int timeout, out int error);
 
-#if !NET_2_1 || MONOTOUCH
                /* This overload is needed as the async Connect method
                 * also needs to check the socket error status, but
                 * getsockopt(..., SO_ERROR) clears the error.
@@ -598,7 +599,7 @@ namespace System.Net.Sockets {
                        
                        return result;
                }
-#endif
+
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern static int Receive_internal(IntPtr sock,
                                                           byte[] buffer,
@@ -686,10 +687,12 @@ namespace System.Net.Sockets {
                        if (disposed && closed)
                                throw new ObjectDisposedException (GetType ().ToString ());
 
+                       if (!connected)
+                               throw new SocketException (10057); // Not connected
+
                        int error;
                        
                        Shutdown_internal (socket, how, out error);
-
                        if (error != 0)
                                throw new SocketException (error);
                }
@@ -722,7 +725,7 @@ namespace System.Net.Sockets {
 #endif
                }
 
-#if NET_2_1 && !MONOTOUCH
+#if MOONLIGHT
                static void CheckConnect (SocketAsyncEventArgs e)
                {
                        // NO check is made whether e != null in MS.NET (NRE is thrown in such case)