Skip to content

Commit

Permalink
[System] Set exception on Finish*Failure in SocketAsyncEventArgs (#6462)
Browse files Browse the repository at this point in the history
Follow up to #6431, we should
capture the exception that is passed to the methods.

Copied the SetResult() method that referencesource uses.

(cherry picked from commit ad5703a)
  • Loading branch information
akoeplinger authored and marek-safar committed Jan 9, 2018
1 parent 253f2e9 commit 3f5fd42
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ internal void StartOperationWrapperConnect (MultipleConnectAsync args)

internal void FinishConnectByNameSyncFailure (Exception exception, int bytesTransferred, SocketFlags flags)
{
SetResults (exception, bytesTransferred, flags);

if (current_socket != null)
current_socket.is_connected = false;

Expand All @@ -257,6 +259,8 @@ internal void FinishConnectByNameSyncFailure (Exception exception, int bytesTran

internal void FinishOperationAsyncFailure (Exception exception, int bytesTransferred, SocketFlags flags)
{
SetResults (exception, bytesTransferred, flags);

if (current_socket != null)
current_socket.is_connected = false;

Expand All @@ -274,8 +278,29 @@ internal void FinishWrapperConnectSuccess (Socket connectSocket, int bytesTransf
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;
}
}
}
}

0 comments on commit 3f5fd42

Please sign in to comment.