var socket = new Socket(address.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
if (address.IsIPv4MappedToIPv6) socket.DualMode = true;
socket.BindToAnonymousPort(address);
+ ConfigureNonBlocking(socket);
Task receiveTask = ReceiveAsync(socket, new ArraySegment<byte>(new byte[1]));
using var left = useClone ? new Socket(origLeft.SafeHandle) : origLeft;
using var right = useClone ? new Socket(origRight.SafeHandle) : origRight;
+ // Force non-blocking mode in ...SyncForceNonBlocking variants of the test:
+ ConfigureNonBlocking(left);
+ ConfigureNonBlocking(right);
+
var leftEndpoint = (IPEndPoint)left.LocalEndPoint;
var rightEndpoint = (IPEndPoint)right.LocalEndPoint;
public virtual bool SupportsAcceptIntoExistingSocket => true;
public virtual bool SupportsAcceptReceive => false;
public virtual void Listen(Socket s, int backlog) { s.Listen(backlog); }
+ public virtual void ConfigureNonBlocking(Socket s) { }
}
public class SocketHelperArraySync : SocketHelperBase
s.Listen(backlog);
s.ForceNonBlocking(true);
}
+ public override void ConfigureNonBlocking(Socket s) => s.ForceNonBlocking(true);
}
public sealed class SocketHelperApm : SocketHelperBase
public bool SupportsAcceptIntoExistingSocket => _socketHelper.SupportsAcceptIntoExistingSocket;
public bool SupportsAcceptReceive => _socketHelper.SupportsAcceptReceive;
public void Listen(Socket s, int backlog) => _socketHelper.Listen(s, backlog);
+ public void ConfigureNonBlocking(Socket s) => _socketHelper.ConfigureNonBlocking(s);
}
public class SocketHelperSpanSync : SocketHelperArraySync
Task.Run(() => { s.ForceNonBlocking(true); Socket accepted = s.Accept(); accepted.ForceNonBlocking(true); return accepted; });
public override Task ConnectAsync(Socket s, EndPoint endPoint) =>
Task.Run(() => { s.ForceNonBlocking(true); s.Connect(endPoint); });
+ public override void ConfigureNonBlocking(Socket s) => s.ForceNonBlocking(true);
}
public sealed class SocketHelperMemoryArrayTask : SocketHelperTask