Skip to content

Commit

Permalink
refactor old APM [Begin/End]Accept methods on top of Task APIs, and e…
Browse files Browse the repository at this point in the history
…nable for Unix as well (#51212)

* refactor old APM [Begin/End]Accept methods on top of Task APIs, and enable for Unix as well

* fix BeginAccept to throw synchronously, and relevant test changes

* fix AcceptReceive test to run on unix too

* dispose accepted socket if receive throws

* remove CallbackClosure cache

* fix test helper to indicate AcceptReceive with EAP is still only supported on Windows

Co-authored-by: Geoffrey Kizer <geoffrek@windows.microsoft.com>
  • Loading branch information
geoffkizer and Geoffrey Kizer authored Apr 26, 2021
1 parent fced2bd commit 5902515
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 556 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<Compile Include="System\Net\Sockets\TransmitFileOptions.cs" />
<Compile Include="System\Net\Sockets\UDPClient.cs" />
<Compile Include="System\Net\Sockets\UdpReceiveResult.cs" />
<Compile Include="System\Net\Sockets\AcceptOverlappedAsyncResult.cs" />
<Compile Include="System\Net\Sockets\BaseOverlappedAsyncResult.cs" />
<Compile Include="System\Net\Sockets\UnixDomainSocketEndPoint.cs" />
<!-- Logging -->
Expand Down Expand Up @@ -89,7 +88,6 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<!-- Windows: CoreCLR -->
<Compile Include="System\Net\Sockets\AcceptOverlappedAsyncResult.Windows.cs" />
<Compile Include="System\Net\Sockets\BaseOverlappedAsyncResult.Windows.cs" />
<Compile Include="System\Net\Sockets\DynamicWinsockMethods.cs" />
<Compile Include="System\Net\Sockets\SafeSocketHandle.Windows.cs" />
Expand Down Expand Up @@ -184,7 +182,6 @@
Link="Common\System\Net\CompletionPortHelper.Windows.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true'">
<Compile Include="System\Net\Sockets\AcceptOverlappedAsyncResult.Unix.cs" />
<Compile Include="System\Net\Sockets\BaseOverlappedAsyncResult.Unix.cs" />
<Compile Include="System\Net\Sockets\SafeSocketHandle.Unix.cs" />
<Compile Include="System\Net\Sockets\Socket.Unix.cs" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,6 @@ public SocketInformation DuplicateAndClose(int targetProcessId)
throw new PlatformNotSupportedException(SR.net_sockets_duplicateandclose_notsupported);
}

public IAsyncResult BeginAccept(int receiveSize, AsyncCallback? callback, object? state)
{
throw new PlatformNotSupportedException(SR.net_sockets_accept_receive_apm_notsupported);
}

public IAsyncResult BeginAccept(Socket? acceptSocket, int receiveSize, AsyncCallback? callback, object? state)
{
throw new PlatformNotSupportedException(SR.net_sockets_accept_receive_apm_notsupported);
}

public Socket EndAccept(out byte[] buffer, IAsyncResult asyncResult)
{
throw new PlatformNotSupportedException(SR.net_sockets_accept_receive_apm_notsupported);
}

public Socket EndAccept(out byte[] buffer, out int bytesTransferred, IAsyncResult asyncResult)
{
throw new PlatformNotSupportedException(SR.net_sockets_accept_receive_apm_notsupported);
}

internal bool PreferInlineCompletions
{
get => _handle.PreferInlineCompletions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Versioning;

namespace System.Net.Sockets
Expand Down Expand Up @@ -145,30 +146,6 @@ public SocketInformation DuplicateAndClose(int targetProcessId)
return info;
}

public IAsyncResult BeginAccept(int receiveSize, AsyncCallback? callback, object? state)
{
return BeginAccept(acceptSocket: null, receiveSize, callback, state);
}

// This is the truly async version that uses AcceptEx.
public IAsyncResult BeginAccept(Socket? acceptSocket, int receiveSize, AsyncCallback? callback, object? state)
{
return BeginAcceptCommon(acceptSocket, receiveSize, callback, state);
}

public Socket EndAccept(out byte[] buffer, IAsyncResult asyncResult)
{
Socket socket = EndAccept(out byte[] innerBuffer, out int bytesTransferred, asyncResult);
buffer = new byte[bytesTransferred];
Buffer.BlockCopy(innerBuffer, 0, buffer, 0, bytesTransferred);
return socket;
}

public Socket EndAccept(out byte[] buffer, out int bytesTransferred, IAsyncResult asyncResult)
{
return EndAcceptCommon(out buffer!, out bytesTransferred, asyncResult);
}

private DynamicWinsockMethods GetDynamicWinsockMethods()
{
return _dynamicWinsockMethods ??= DynamicWinsockMethods.GetMethods(_addressFamily, _socketType, _protocolType);
Expand Down Expand Up @@ -439,7 +416,7 @@ private IAsyncResult BeginSendFileInternal(string? fileName, byte[]? preBuffer,
throw new SocketException((int)errorCode);
}

asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
asyncResult.FinishPostingAsyncOp();

return asyncResult;
}
Expand Down
Loading

0 comments on commit 5902515

Please sign in to comment.