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" />
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"
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()
{