-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Description
After setting / using SocketAsyncEventArgs.BufferList we should be able to revert to single-buffer mode by calling:
saea.BufferList = null;
saea.SetBuffer(...);While working on UDP test harmonization, I discovered that this does not work with ReceiveMessageFrom on Linux. Haven't checked other Unixes.
Repro:
[Fact]
public void ReceiveMessageFromIssue()
{
using var receiver = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
using var sender = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
using var saea = new SocketAsyncEventArgs();
var completed = new ManualResetEventSlim();
saea.Completed += delegate { completed.Set(); };
receiver.Bind(new IPEndPoint(IPAddress.Loopback, 0));
sender.Bind(new IPEndPoint(IPAddress.Loopback, 0));
saea.RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
// Commenting out the following line makes the issue disappear:
saea.BufferList = new List<ArraySegment<byte>> { new ArraySegment<byte>(new byte[1]) };
saea.BufferList = null;
saea.SetBuffer(new byte[1024], 0, 1024);
sender.SendTo(new byte[1024], receiver.LocalEndPoint);
if (receiver.ReceiveMessageFromAsync(saea))
Assert.True(completed.Wait(1000), "Expected operation to complete within timeout");
// Fails on Linux, works on Windows:
Assert.Equal(1024, saea.BytesTransferred);
}Reactions are currently unavailable