Make sure TcpClient.ExclusiveAddressUse throws on Unix
authorPetr Onderka <gsvick@gmail.com>
Thu, 7 Jul 2016 16:14:50 +0000 (17:14 +0100)
committerPetr Onderka <gsvick@gmail.com>
Thu, 7 Jul 2016 16:14:50 +0000 (17:14 +0100)
Commit migrated from https://github.com/dotnet/corefx/commit/4e94c9279aa7fe7b0d050494c2d2948f7b9dc150

src/libraries/System.Net.Sockets/src/System/Net/Sockets/TCPClient.Unix.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpClientTest.cs

index b0f18bb..e409d4d 100644 (file)
@@ -378,10 +378,9 @@ namespace System.Net.Sockets
                 ShadowOptions so = EnsureShadowValuesInitialized();
                 so._exclusiveAddressUse = value ? 1 : 0;
                 so._exclusiveAddressUseInitialized = true;
-                if (_clientSocket != null)
-                {
-                    _clientSocket.ExclusiveAddressUse = value; // Use setter explicitly as it does additional validation beyond that done by SetOption
-                }
+
+                Socket s = _clientSocket ?? CreateSocket();
+                s.ExclusiveAddressUse = value; // Use setter explicitly as it does additional validation beyond that done by SetOption
             }
         }
 
index f9ed620..708e4cb 100644 (file)
@@ -69,6 +69,7 @@ namespace System.Net.Sockets.Tests
         }
 
         [Fact]
+        [PlatformSpecific(PlatformID.Windows)]
         public void Roundtrip_ExclusiveAddressUse_GetEqualsSet()
         {
             using (TcpClient client = new TcpClient())
@@ -81,6 +82,20 @@ namespace System.Net.Sockets.Tests
         }
 
         [Fact]
+        [PlatformSpecific(PlatformID.AnyUnix)]
+        public void ExclusiveAddressUse_NotSupported()
+        {
+            using (TcpClient client = new TcpClient())
+            {
+                Assert.Throws<SocketException>(() => client.ExclusiveAddressUse);
+                Assert.Throws<SocketException>(() =>
+                {
+                    client.ExclusiveAddressUse = true;
+                });
+            }
+        }
+
+        [Fact]
         public void Roundtrip_LingerOption_GetEqualsSet()
         {
             using (TcpClient client = new TcpClient())