You've already forked linux-packaging-mono
Imported Upstream version 6.0.0.172
Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
parent
8016999e4d
commit
64ac736ec5
@ -227,9 +227,9 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandle.Dispose();
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -261,9 +261,9 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandle.Dispose();
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -296,13 +296,13 @@ namespace System.Net.Sockets
|
||||
{
|
||||
fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span))
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None, $"Expected None, got {_singleBufferHandleState}");
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
NativeOverlapped* overlapped = AllocateNativeOverlapped();
|
||||
try
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None, $"Expected None, got {_singleBufferHandleState}");
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
SocketFlags flags = _socketFlags;
|
||||
SocketError socketError = Interop.Winsock.WSARecv(
|
||||
handle.DangerousGetHandle(), // to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
|
||||
@ -318,8 +318,8 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -368,13 +368,13 @@ namespace System.Net.Sockets
|
||||
{
|
||||
fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span))
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None);
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
NativeOverlapped* overlapped = AllocateNativeOverlapped();
|
||||
try
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None);
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
SocketFlags flags = _socketFlags;
|
||||
SocketError socketError = Interop.Winsock.WSARecvFrom(
|
||||
handle.DangerousGetHandle(), // to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
|
||||
@ -392,8 +392,8 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -549,9 +549,9 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandle.Dispose();
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -564,13 +564,13 @@ namespace System.Net.Sockets
|
||||
{
|
||||
fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span))
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None);
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
NativeOverlapped* overlapped = AllocateNativeOverlapped();
|
||||
try
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None);
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
SocketError socketError = Interop.Winsock.WSASend(
|
||||
handle.DangerousGetHandle(), // to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
|
||||
ref wsaBuffer,
|
||||
@ -585,8 +585,8 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -738,13 +738,13 @@ namespace System.Net.Sockets
|
||||
{
|
||||
fixed (byte* bufferPtr = &MemoryMarshal.GetReference(_buffer.Span))
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None);
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
NativeOverlapped* overlapped = AllocateNativeOverlapped();
|
||||
try
|
||||
{
|
||||
Debug.Assert(_singleBufferHandleState == SingleBufferHandleState.None);
|
||||
_singleBufferHandleState = SingleBufferHandleState.InProcess;
|
||||
var wsaBuffer = new WSABuffer { Length = _count, Pointer = (IntPtr)(bufferPtr + _offset) };
|
||||
|
||||
SocketError socketError = Interop.Winsock.WSASendTo(
|
||||
handle.DangerousGetHandle(), // to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
|
||||
ref wsaBuffer,
|
||||
@ -761,8 +761,8 @@ namespace System.Net.Sockets
|
||||
}
|
||||
catch
|
||||
{
|
||||
FreeNativeOverlapped(overlapped);
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
FreeNativeOverlapped(overlapped);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -916,8 +916,8 @@ namespace System.Net.Sockets
|
||||
|
||||
if (_singleBufferHandleState != SingleBufferHandleState.None)
|
||||
{
|
||||
_singleBufferHandle.Dispose();
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
_singleBufferHandle.Dispose();
|
||||
}
|
||||
|
||||
if (_multipleBufferGCHandles != null)
|
||||
@ -1142,8 +1142,8 @@ namespace System.Net.Sockets
|
||||
|
||||
if (_singleBufferHandleState == SingleBufferHandleState.Set)
|
||||
{
|
||||
_singleBufferHandle.Dispose();
|
||||
_singleBufferHandleState = SingleBufferHandleState.None;
|
||||
_singleBufferHandle.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -380,14 +380,15 @@ namespace System.Net.Sockets
|
||||
|
||||
receivedFlags = messageHeader.Flags;
|
||||
sockAddrLen = messageHeader.SocketAddressLen;
|
||||
ipPacketInformation = GetIPPacketInformation(&messageHeader, isIPv4, isIPv6);
|
||||
}
|
||||
|
||||
if (errno != Interop.Error.SUCCESS)
|
||||
{
|
||||
ipPacketInformation = default(IPPacketInformation);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipPacketInformation = GetIPPacketInformation(&messageHeader, isIPv4, isIPv6);
|
||||
socketAddressLen = sockAddrLen;
|
||||
return checked((int)received);
|
||||
}
|
||||
@ -442,15 +443,16 @@ namespace System.Net.Sockets
|
||||
|
||||
receivedFlags = messageHeader.Flags;
|
||||
int sockAddrLen = messageHeader.SocketAddressLen;
|
||||
ipPacketInformation = GetIPPacketInformation(&messageHeader, isIPv4, isIPv6);
|
||||
|
||||
if (errno == Interop.Error.SUCCESS)
|
||||
{
|
||||
ipPacketInformation = GetIPPacketInformation(&messageHeader, isIPv4, isIPv6);
|
||||
socketAddressLen = sockAddrLen;
|
||||
return checked((int)received);
|
||||
}
|
||||
else
|
||||
{
|
||||
ipPacketInformation = default(IPPacketInformation);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -837,6 +837,90 @@ namespace System.Net.Sockets.Tests
|
||||
Assert.Equal(e.SocketErrorCode, SocketError.InvalidArgument);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendAsync_ConcurrentDispose_SucceedsOrThrowsAppropriateException()
|
||||
{
|
||||
if (UsesSync) return;
|
||||
|
||||
for (int i = 0; i < 20; i++) // run multiple times to attempt to force various interleavings
|
||||
{
|
||||
(Socket client, Socket server) = CreateConnectedSocketPair();
|
||||
using (client)
|
||||
using (server)
|
||||
using (var b = new Barrier(2))
|
||||
{
|
||||
Task dispose = Task.Factory.StartNew(() =>
|
||||
{
|
||||
b.SignalAndWait();
|
||||
client.Dispose();
|
||||
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
|
||||
Task send = Task.Factory.StartNew(() =>
|
||||
{
|
||||
b.SignalAndWait();
|
||||
SendAsync(client, new ArraySegment<byte>(new byte[1])).GetAwaiter().GetResult();
|
||||
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
|
||||
await dispose;
|
||||
Exception error = await Record.ExceptionAsync(() => send);
|
||||
if (error != null)
|
||||
{
|
||||
Assert.True(error is ObjectDisposedException || error is SocketException, error.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReceiveAsync_ConcurrentDispose_SucceedsOrThrowsAppropriateException()
|
||||
{
|
||||
if (UsesSync) return;
|
||||
|
||||
for (int i = 0; i < 20; i++) // run multiple times to attempt to force various interleavings
|
||||
{
|
||||
(Socket client, Socket server) = CreateConnectedSocketPair();
|
||||
using (client)
|
||||
using (server)
|
||||
using (var b = new Barrier(2))
|
||||
{
|
||||
Task dispose = Task.Factory.StartNew(() =>
|
||||
{
|
||||
b.SignalAndWait();
|
||||
client.Dispose();
|
||||
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
|
||||
Task send = Task.Factory.StartNew(() =>
|
||||
{
|
||||
SendAsync(server, new ArraySegment<byte>(new byte[1])).GetAwaiter().GetResult();
|
||||
b.SignalAndWait();
|
||||
ReceiveAsync(client, new ArraySegment<byte>(new byte[1])).GetAwaiter().GetResult();
|
||||
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
|
||||
await dispose;
|
||||
Exception error = await Record.ExceptionAsync(() => send);
|
||||
if (error != null)
|
||||
{
|
||||
Assert.True(error is ObjectDisposedException || error is SocketException, error.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static (Socket, Socket) CreateConnectedSocketPair()
|
||||
{
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
listener.Listen(1);
|
||||
|
||||
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
client.Connect(listener.LocalEndPoint);
|
||||
Socket server = listener.Accept();
|
||||
|
||||
return (client, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SendReceive
|
||||
@ -1248,21 +1332,6 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
}).Dispose();
|
||||
}
|
||||
|
||||
private static (Socket, Socket) CreateConnectedSocketPair()
|
||||
{
|
||||
using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
|
||||
listener.Listen(1);
|
||||
|
||||
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
client.Connect(listener.LocalEndPoint);
|
||||
Socket server = listener.Accept();
|
||||
|
||||
return (client, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SendReceiveSyncForceNonBlocking : SendReceive<SocketHelperSyncForceNonBlocking> { }
|
||||
|
@ -84,7 +84,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
|
||||
public async Task MulticastInterface_Set_AnyInterface_Succeeds()
|
||||
{
|
||||
// On all platforms, index 0 means "any interface"
|
||||
@ -92,7 +92,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
|
||||
[PlatformSpecific(TestPlatforms.Windows)] // see comment below
|
||||
[ActiveIssue(21327, TargetFrameworkMonikers.Uap)] // UWP Apps are forbidden to send network traffic to the local Computer.
|
||||
public async Task MulticastInterface_Set_Loopback_Succeeds()
|
||||
@ -151,7 +151,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
|
||||
public async Task MulticastInterface_Set_IPv6_AnyInterface_Succeeds()
|
||||
{
|
||||
if (PlatformDetection.IsFedora || PlatformDetection.IsRedHatFamily7 || PlatformDetection.IsOSX)
|
||||
@ -164,7 +164,7 @@ namespace System.Net.Sockets.Tests
|
||||
}
|
||||
|
||||
[OuterLoop] // TODO: Issue #11345
|
||||
[Fact]
|
||||
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // ActiveIssue: dotnet/corefx #29929
|
||||
[PlatformSpecific(TestPlatforms.Windows)]
|
||||
[ActiveIssue(21327, TargetFrameworkMonikers.Uap)] // UWP Apps are forbidden to send network traffic to the local Computer.
|
||||
public async void MulticastInterface_Set_IPv6_Loopback_Succeeds()
|
||||
|
Reference in New Issue
Block a user