Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map TcpListener APM methods to Task-based methods #40476

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
Link="Common\System\Net\SocketAddress.cs" />
<Compile Include="$(CommonPath)System\Net\TcpValidationHelpers.cs"
Link="Common\System\Net\TcpValidationHelpers.cs" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs"
Link="Common\System\Threading\Tasks\TaskToApm.cs" />
<!-- System.Net.Internals -->
<Compile Include="$(CommonPath)System\Net\Internals\IPEndPointExtensions.cs"
Link="Common\System\Net\Internals\IPEndPointExtensions.cs" />
Expand Down Expand Up @@ -215,8 +217,6 @@
Link="Common\System\Net\SocketProtocolSupportPal.Unix" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketErrorPal.Unix.cs"
Link="Common\System\Net\Sockets\SocketErrorPal.Unix" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs"
Link="Common\System\Threading\Tasks\TaskToApm.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Link="Common\Interop\Unix\Interop.Errors.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,40 +207,17 @@ public TcpClient AcceptTcpClient()
return new TcpClient(acceptedSocket);
}

public IAsyncResult BeginAcceptSocket(AsyncCallback? callback, object? state)
{

if (!_active)
{
throw new InvalidOperationException(SR.net_stopped);
}

return _serverSocket!.BeginAccept(callback, state);
}
public IAsyncResult BeginAcceptSocket(AsyncCallback? callback, object? state) =>
TaskToApm.Begin(AcceptSocketAsync(), callback, state);

public Socket EndAcceptSocket(IAsyncResult asyncResult)
{
if (asyncResult == null)
{
throw new ArgumentNullException(nameof(asyncResult));
}

LazyAsyncResult? lazyResult = asyncResult as LazyAsyncResult;
Socket? asyncSocket = lazyResult == null ? null : lazyResult.AsyncObject as Socket;
if (asyncSocket == null)
{
throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
}

// This will throw ObjectDisposedException if Stop() has been called.
return asyncSocket.EndAccept(asyncResult);
}
public Socket EndAcceptSocket(IAsyncResult asyncResult) =>
TaskToApm.End<Socket>(asyncResult);

public IAsyncResult BeginAcceptTcpClient(AsyncCallback? callback, object? state) =>
BeginAcceptSocket(callback, state);
TaskToApm.Begin(AcceptTcpClientAsync(), callback, state);

public TcpClient EndAcceptTcpClient(IAsyncResult asyncResult) =>
new TcpClient(EndAcceptSocket(asyncResult));
TaskToApm.End<TcpClient>(asyncResult);

public Task<Socket> AcceptSocketAsync()
{
Expand Down