[System] Test Socket TCP double bind.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Thu, 10 Sep 2015 16:25:51 +0000 (17:25 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Mon, 14 Sep 2015 09:45:47 +0000 (10:45 +0100)
Test checks that when setting TCP socket option ReuseAddress, it is
possible to bind other sockets to the same endpoint.

Covers #31557.

mcs/class/System/Test/System.Net.Sockets/SocketTest.cs

index f8c2f4cb750d69cbda8d81e1312338786dae656f..59e3f322dd87722098b2661868ee3cd268f44676 100755 (executable)
@@ -3476,7 +3476,29 @@ namespace MonoTests.System.Net.Sockets
                        ss.Close ();
                        s.Close ();
                }
-               
+
+               // Test case for bug #31557
+               [Test]
+               public void TcpDoubleBind ()
+               {
+                       using (Socket s = new Socket (AddressFamily.InterNetwork,
+                                               SocketType.Stream, ProtocolType.Tcp))
+                       using (Socket ss = new Socket (AddressFamily.InterNetwork,
+                                               SocketType.Stream, ProtocolType.Tcp)) {
+                               s.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
+
+                               s.Bind (new IPEndPoint (IPAddress.Any, 12345));
+                               s.Listen(1);
+
+                               ss.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
+
+                               ss.Bind (new IPEndPoint (IPAddress.Any, 12345));
+                               ss.Listen(1);
+
+                               // If we make it this far, we succeeded.
+                       }
+               }
+
                [Test]
                [Category ("NotOnMac")]
                 public void ConnectedProperty ()