Quellcode durchsuchen

* TcpClient.cs: Do not initialize network stream in Connect. In
Dispose, only nullify client if network stream was not obtained.
Fixes bug #81105.
* TcpClientTest.cs: Added test for bug #81105.

svn path=/trunk/mcs/; revision=74062

Gert Driesen vor 19 Jahren
Ursprung
Commit
155199945b

+ 6 - 0
mcs/class/System/System.Net.Sockets/ChangeLog

@@ -1,3 +1,9 @@
+2007-03-11  Gert Driesen  <[email protected]>
+
+	* TcpClient.cs: Do not initialize network stream in Connect. In
+	Dispose, only nullify client if network stream was not obtained.
+	Fixes bug #81105.
+
 2007-01-30  Ilya Kharmatsky <ilyak -at- mainsoft.com>
 
 	* Socket.jvm.cs: additional stubs for net_2_0 properties,

+ 3 - 4
mcs/class/System/System.Net.Sockets/TcpClient.cs

@@ -276,7 +276,6 @@ namespace System.Net.Sockets
 		{
 			try {
 				client.Connect(remote_end_point);
-				stream = new NetworkStream(client, true);
 				active = true;
 			} finally {
 				CheckDisposed ();
@@ -416,7 +415,7 @@ namespace System.Net.Sockets
 				return;
 			disposed = true;
 
-			if (disposing){
+			if (disposing) {
 				// release managed resources
 				NetworkStream s = stream;
 				stream = null;
@@ -428,8 +427,8 @@ namespace System.Net.Sockets
 					s = null;
 				} else if (client != null){
 					client.Close ();
+					client = null;
 				}
-				client = null;
 			}
 		}
 		
@@ -452,7 +451,7 @@ namespace System.Net.Sockets
 		{
 			if (disposed)
 				throw new ObjectDisposedException (GetType().FullName);
-		}		
+		}
 	}
 }
 

+ 4 - 0
mcs/class/System/Test/System.Net.Sockets/ChangeLog

@@ -1,3 +1,7 @@
+2007-03-11  Gert Driesen  <[email protected]>
+
+	* TcpClientTest.cs: Added test for bug #81105.
+
 2007-03-07  Vladimir Krasnov  <[email protected]>
 
 	* SocketTest.jvm.cs: removed not supported calls for TARGET_JVM because

+ 75 - 1
mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs

@@ -70,7 +70,81 @@ namespace MonoTests.System.Net.Sockets {
 			outClient.Close();
 			lSock.Close();
 			
-		}	
+		}
+
+		[Test] // bub #81105
+		public void CloseTest ()
+		{
+			IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8765);
+			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
+				sr.Start ();
+
+				TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
+				NetworkStream ns = tcpClient.GetStream ();
+				Assert.IsNotNull (ns, "#A1");
+#if NET_2_0
+				Assert.AreEqual (0, tcpClient.Available, "#A2");
+				Assert.IsTrue (tcpClient.Connected, "#A3");
+				// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#A4");
+#endif
+				tcpClient.Close ();
+#if NET_2_0
+				Assert.IsNotNull (tcpClient.Client, "#A5");
+				try {
+					int available = tcpClient.Available;
+					Assert.Fail ("#A6: " + available);
+				} catch (ObjectDisposedException) {
+				}
+				Assert.IsFalse (tcpClient.Connected, "#A7");
+				// not supported on linux
+				/*
+				try {
+					bool exclusive = tcpClient.ExclusiveAddressUse;
+					Assert.Fail ("#A8: " + exclusive);
+				} catch (ObjectDisposedException) {
+				}
+				*/
+#endif
+			}
+
+			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
+				sr.Start ();
+
+				TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
+#if NET_2_0
+				Assert.AreEqual (0, tcpClient.Available, "#B1");
+				Assert.IsTrue (tcpClient.Connected, "#B2");
+				// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#B3");
+#endif
+				tcpClient.Close ();
+#if NET_2_0
+				Assert.IsNull (tcpClient.Client, "#B4");
+				try {
+					int available = tcpClient.Available;
+					Assert.Fail ("#B5: " + available);
+				} catch (NullReferenceException) {
+				}
+				try {
+					bool connected = tcpClient.Connected;
+					Assert.Fail ("#B6: " + connected);
+				} catch (NullReferenceException) {
+				}
+				// not supported on linux
+				/*
+				try {
+					bool exclusive = tcpClient.ExclusiveAddressUse;
+					Assert.Fail ("#B7: " + exclusive);
+				} catch (NullReferenceException) {
+				}
+				*/
+#endif
+			}
+		}
+
+		byte [] CloseRequestHandler (Socket socket)
+		{
+			return new byte [0];
+		}
 
 #if NET_2_0
 		[Test]