Skip to content

Commit 3f5fd42

Browse files
akoeplingermarek-safar
authored andcommitted
[System] Set exception on Finish*Failure in SocketAsyncEventArgs (#6462)
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)
1 parent 253f2e9 commit 3f5fd42

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

mcs/class/System/System.Net.Sockets/SocketAsyncEventArgs.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ internal void StartOperationWrapperConnect (MultipleConnectAsync args)
249249

250250
internal void FinishConnectByNameSyncFailure (Exception exception, int bytesTransferred, SocketFlags flags)
251251
{
252+
SetResults (exception, bytesTransferred, flags);
253+
252254
if (current_socket != null)
253255
current_socket.is_connected = false;
254256

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

258260
internal void FinishOperationAsyncFailure (Exception exception, int bytesTransferred, SocketFlags flags)
259261
{
262+
SetResults (exception, bytesTransferred, flags);
263+
260264
if (current_socket != null)
261265
current_socket.is_connected = false;
262266

@@ -274,8 +278,29 @@ internal void FinishWrapperConnectSuccess (Socket connectSocket, int bytesTransf
274278
internal void SetResults (SocketError socketError, int bytesTransferred, SocketFlags flags)
275279
{
276280
SocketError = socketError;
281+
ConnectByNameError = null;
282+
BytesTransferred = bytesTransferred;
283+
SocketFlags = flags;
284+
}
285+
286+
internal void SetResults (Exception exception, int bytesTransferred, SocketFlags flags)
287+
{
288+
ConnectByNameError = exception;
277289
BytesTransferred = bytesTransferred;
278290
SocketFlags = flags;
291+
292+
if (exception == null)
293+
{
294+
SocketError = SocketError.Success;
295+
}
296+
else
297+
{
298+
var socketException = exception as SocketException;
299+
if (socketException != null)
300+
SocketError = socketException.SocketErrorCode;
301+
else
302+
SocketError = SocketError.SocketError;
303+
}
279304
}
280305
}
281306
}

0 commit comments

Comments
 (0)