Skip to content

Commit

Permalink
Relax Socket.DualMode exception behavior (#50585)
Browse files Browse the repository at this point in the history
Stop throwing from Socket.DualMode getter for IPV4 sockets, return false instead.
  • Loading branch information
antonfirsov authored May 11, 2021
1 parent d2c744f commit 753b764
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ public bool DualMode
{
if (AddressFamily != AddressFamily.InterNetworkV6)
{
throw new NotSupportedException(SR.net_invalidversion);
return false;
}
return ((int)GetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only)! == 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ public void NormalConstructor_DualModeConfgiureable()
}

[Fact]
public void IPv4Constructor_DualModeThrows()
public void IPv4Constructor_DualMode_GetterReturnsFalse()
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
Assert.Throws<NotSupportedException>(() =>
{
Assert.False(socket.DualMode);
});
Assert.False(socket.DualMode);
}
}

[Fact]
public void IPv4Constructor_DualMode_SetterThrows()
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
Assert.Throws<NotSupportedException>(() =>
{
socket.DualMode = true;
Expand Down

0 comments on commit 753b764

Please sign in to comment.