From: Geoff Kizer Date: Thu, 6 Aug 2020 19:20:25 +0000 (-0700) Subject: map TcpListener APM methods to Task-based methods (#40476) X-Git-Tag: submit/tizen/20210909.063632~6176 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2021d54c49da2864d85d4ba5188729365410a228;p=platform%2Fupstream%2Fdotnet%2Fruntime.git map TcpListener APM methods to Task-based methods (#40476) Co-authored-by: Geoffrey Kizer --- diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj index 3d4d3c7..ae0f96d 100644 --- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj +++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj @@ -80,6 +80,8 @@ Link="Common\System\Net\SocketAddress.cs" /> + @@ -215,8 +217,6 @@ Link="Common\System\Net\SocketProtocolSupportPal.Unix" /> - + 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(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(asyncResult); public Task AcceptSocketAsync() {