Remove FromAsync usage from SendPacketsAsync on Unix (#35513)
authorStephen Toub <stoub@microsoft.com>
Sat, 2 May 2020 16:02:25 +0000 (12:02 -0400)
committerGitHub <noreply@github.com>
Sat, 2 May 2020 16:02:25 +0000 (12:02 -0400)
This call is in the Unix implementation, and the Unix implementation of DisconnectAsync just calls the synchronous Disconnect... so we can just call it directly and skip all the unnecessary layering.

src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs

index adf1303229d806f0f200eec36be900ec807668c6..68f8c82df2956ed9eb07410acf4281d7e0ca2ed7 100644 (file)
@@ -1756,11 +1756,11 @@ namespace System.Net.Sockets
 
                 if ((options & (TransmitFileOptions.Disconnect | TransmitFileOptions.ReuseSocket)) != 0)
                 {
-                    await Task.Factory.FromAsync(
-                        (reuse, c, s) => ((Socket)s!).BeginDisconnect(reuse, c, s),
-                        iar => ((Socket)iar.AsyncState!).EndDisconnect(iar),
-                        (options & TransmitFileOptions.ReuseSocket) != 0,
-                        socket).ConfigureAwait(false);
+                    error = Disconnect(socket, socket.InternalSafeHandle, (options & TransmitFileOptions.ReuseSocket) != 0);
+                    if (error != SocketError.Success)
+                    {
+                        throw new SocketException((int)error);
+                    }
                 }
             }
             catch (Exception exc)