From 3f5fd4287be28a32314262a6f8dcb5bdde86e0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Tue, 9 Jan 2018 15:45:47 +0100 Subject: [System] Set exception on Finish*Failure in SocketAsyncEventArgs (#6462) Follow up to https://github.com/mono/mono/pull/6431, we should capture the exception that is passed to the methods. Copied the SetResult() method that referencesource uses. (cherry picked from commit ad5703adfd84c309292d4c33a2fcaa5e60de9100) --- .../System.Net.Sockets/SocketAsyncEventArgs.cs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs b/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs index 534aff06207..d2c86104408 100644 --- a/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs +++ b/mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs @@ -249,6 +249,8 @@ namespace System.Net.Sockets internal void FinishConnectByNameSyncFailure (Exception exception, int bytesTransferred, SocketFlags flags) { + SetResults (exception, bytesTransferred, flags); + if (current_socket != null) current_socket.is_connected = false; @@ -257,6 +259,8 @@ namespace System.Net.Sockets internal void FinishOperationAsyncFailure (Exception exception, int bytesTransferred, SocketFlags flags) { + SetResults (exception, bytesTransferred, flags); + if (current_socket != null) current_socket.is_connected = false; @@ -274,8 +278,29 @@ namespace System.Net.Sockets internal void SetResults (SocketError socketError, int bytesTransferred, SocketFlags flags) { SocketError = socketError; + ConnectByNameError = null; + BytesTransferred = bytesTransferred; + SocketFlags = flags; + } + + internal void SetResults (Exception exception, int bytesTransferred, SocketFlags flags) + { + ConnectByNameError = exception; BytesTransferred = bytesTransferred; SocketFlags = flags; + + if (exception == null) + { + SocketError = SocketError.Success; + } + else + { + var socketException = exception as SocketException; + if (socketException != null) + SocketError = socketException.SocketErrorCode; + else + SocketError = SocketError.SocketError; + } } } } -- cgit v1.2.3