Skip to content
Open
32 changes: 29 additions & 3 deletions src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
protected static IPEndPoint GetGetDummyTestEndpoint(AddressFamily addressFamily = AddressFamily.InterNetwork) =>
addressFamily == AddressFamily.InterNetwork ? new IPEndPoint(IPAddress.Parse("1.2.3.4"), 1234) : new IPEndPoint(IPAddress.Parse("1:2:3::4"), 1234);

private static IPEndPoint CreateLoopbackUdpEndpoint(AddressFamily family, out Socket receiver)
{
IPAddress loopback = family == AddressFamily.InterNetwork ? IPAddress.Loopback : IPAddress.IPv6Loopback;
receiver = new Socket(family, SocketType.Dgram, ProtocolType.Udp);
receiver.Bind(new IPEndPoint(loopback, 0)); // ephemeral port on loopback
return (IPEndPoint)receiver.LocalEndPoint!;
}

protected SendTo(ITestOutputHelper output) : base(output)
{
}
Expand Down Expand Up @@ -78,9 +86,11 @@
public async Task Datagram_UDP_ShouldImplicitlyBindLocalEndpoint()
{
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
using Socket receiver;

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration

Check failure on line 89 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L89

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(89,26): error CS0210: (NETCORE_ENGINEERING_TELEMETRY=Build) You must provide an initializer in a fixed or using statement declaration
IPEndPoint remote = CreateLoopbackUdpEndpoint(socket.AddressFamily, out receiver);

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS1657: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot use 'receiver' as a ref or out value because it is a 'using variable'

Check failure on line 90 in src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs

View check run for this annotation

Azure Pipelines / runtime

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs#L90

src/libraries/System.Net.Sockets/tests/FunctionalTests/SendTo.cs(90,85): error CS0165: (NETCORE_ENGINEERING_TELEMETRY=Build) Use of unassigned local variable 'receiver'
byte[] buffer = new byte[32];

Task sendTask = SendToAsync(socket, new ArraySegment<byte>(buffer), GetGetDummyTestEndpoint());
Task sendTask = SendToAsync(socket, new ArraySegment<byte>(buffer), remote);

// Asynchronous calls shall alter the property immediately:
if (!UsesSync)
Expand All @@ -91,7 +101,11 @@
await sendTask;

// In synchronous calls, we should wait for the completion of the helper task:
Assert.NotNull(socket.LocalEndPoint);
EndPoint? local = socket.LocalEndPoint;
Assert.NotNull(local);
var localIp = (IPEndPoint)local!;
Assert.NotEqual(0, localIp.Port);
Assert.True(IPAddress.IsLoopback(localIp.Address), "Implicit bind should select loopback when sending to loopback.");
}

[ConditionalFact]
Expand All @@ -109,7 +123,19 @@
throw new SkipTestException("HostUnreachable indicates missing local network permission; this test might pass or fail depending on the environment. Please verify manually.");
}

Assert.Equal(SocketError.AccessDenied, e.SocketErrorCode);
// On some mobile/restricted queues the send can fail earlier with unreachable
// rather than AccessDenied (see #120526, #114450).
if (OperatingSystem.IsAndroid() || OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS())
{
Assert.True(
e.SocketErrorCode is SocketError.AccessDenied or SocketError.NetworkUnreachable or SocketError.HostUnreachable,
$"Unexpected error: {e.SocketErrorCode}");
}
else
{
Assert.Equal(SocketError.AccessDenied, e.SocketErrorCode);
}

Assert.Null(socket.LocalEndPoint);
}

Expand Down
Loading