Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static partial class PlatformDetection

public static bool IsMonoLinuxArm64 => IsMonoRuntime && IsLinux && IsArm64Process;
public static bool IsNotMonoLinuxArm64 => !IsMonoLinuxArm64;
public static bool IsNotRiscV64Ubuntu => !IsUbuntu || !IsRiscV64Process;

// OSX family
public static bool IsApplePlatform => IsOSX || IsiOS || IstvOS || IsMacCatalyst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,18 +794,20 @@ await Task.WhenAll(

[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)] // API throws PNSE on Unix
[InlineData(0)]
[InlineData(1)]
public void Connect_ConnectTwice_NotSupported(int invalidatingAction)
[InlineData(false)]
[InlineData(true)]
public void Connect_ConnectTwice_NotSupported(bool invalidatingAction)
{
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
switch (invalidatingAction)
// On RISC-V Qemu we omit one test case due to: https://gitlab.com/qemu-project/qemu/-/issues/2410
bool invalidatingActionOnPlatform = invalidatingAction && PlatformDetection.IsNotRiscV64Ubuntu;
switch (invalidatingActionOnPlatform)
{
case 0:
case false:
IntPtr handle = client.Handle; // exposing the underlying handle
break;
case 1:
case true:
client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.Debug, 1); // untracked socket option
break;
}
Expand All @@ -825,20 +827,22 @@ public void Connect_ConnectTwice_NotSupported(int invalidatingAction)

[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)] // API throws PNSE on Unix
[InlineData(0)]
[InlineData(1)]
public void ConnectAsync_ConnectTwice_NotSupported(int invalidatingAction)
[InlineData(false)]
[InlineData(true)]
public void ConnectAsync_ConnectTwice_NotSupported(bool invalidatingAction)
{
AutoResetEvent completed = new AutoResetEvent(false);

using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
switch (invalidatingAction)
// On RISC-V Qemu we omit one test case due to: https://gitlab.com/qemu-project/qemu/-/issues/2410
bool invalidatingActionOnPlatform = invalidatingAction && PlatformDetection.IsNotRiscV64Ubuntu;
switch (invalidatingActionOnPlatform)
{
case 0:
case false:
IntPtr handle = client.Handle; // exposing the underlying handle
break;
case 1:
case true:
client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.Debug, 1); // untracked socket option
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace System.Net.Sockets.Tests
public partial class SocketOptionNameTest
{
private static bool SocketsReuseUnicastPortSupport => Capability.SocketsReuseUnicastPortSupport().HasValue;
private static bool SupportedOnPlatform = PlatformDetection.IsNotWindowsNanoNorServerCore && PlatformDetection.IsNotRiscV64Ubuntu;

[ConditionalFact(nameof(SocketsReuseUnicastPortSupport))]
public void ReuseUnicastPort_CreateSocketGetOption()
Expand Down Expand Up @@ -50,7 +51,7 @@ public void ReuseUnicastPort_CreateSocketSetOption()
}
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotRiscV64Ubuntu))]
public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetSucceeds_GetThrows()
{
int interfaceIndex = 0;
Expand All @@ -64,7 +65,7 @@ public void MulticastOption_CreateSocketSetGetOption_GroupAndInterfaceIndex_SetS
}
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286
[ConditionalFact(nameof(SupportedOnPlatform))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286 and RISC-V Qemu
public async Task MulticastInterface_Set_AnyInterface_Succeeds()
{
// On all platforms, index 0 means "any interface"
Expand Down Expand Up @@ -120,7 +121,7 @@ public void MulticastInterface_Set_InvalidIndex_Throws()
}
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoNorServerCore))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286
[ConditionalFact(nameof(SupportedOnPlatform))] // Skip on Nano: https://github.com/dotnet/runtime/issues/26286 and RISC-V Qemu
[SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD, "Expected behavior is different on OSX or FreeBSD")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/52124", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public async Task MulticastInterface_Set_IPv6_AnyInterface_Succeeds()
Expand Down
10 changes: 9 additions & 1 deletion src/native/libs/System.Native/pal_networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,15 @@ int32_t SystemNative_GetSockOpt(
{
return Error_EFAULT;
}

#if defined(TARGET_RISCV64)
uint8_t nonEmptyOptionValueBuffer;
if (socketOptionLevel == SocketOptionLevel_SOL_TCP && socketOptionName == SocketOptionName_SO_TCP_KEEPALIVE_TIME && optionValue == NULL
&& *optionLen == 0)
{
// It's workaround for Qemu bug: https://gitlab.com/qemu-project/qemu/-/issues/2390.
optionValue = &nonEmptyOptionValueBuffer;
}
#endif
int fd = ToFileDescriptor(socket);

//
Expand Down