Skip to content

Commit

Permalink
SmtpClientTest Assertion Fail Fix (#76361)
Browse files Browse the repository at this point in the history
* Eliminate temporary -1 on Socket.Unix.cs
  • Loading branch information
liveans authored Oct 24, 2022
1 parent bbcff6b commit c092a76
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Win32.SafeHandles;
using System.Reflection;
using System.Collections;
using System.Threading;

namespace System.Net.Sockets
{
Expand Down Expand Up @@ -108,7 +109,7 @@ internal void ReplaceHandleIfNecessaryAfterFailedConnect()
SocketError errorCode = ReplaceHandle();
if (errorCode != SocketError.Success)
{
throw new SocketException((int) errorCode);
throw new SocketException((int)errorCode);
}

_handle.LastConnectFailed = false;
Expand Down Expand Up @@ -137,14 +138,22 @@ internal SocketError ReplaceHandle()

// Then replace the handle with a new one
SafeSocketHandle oldHandle = _handle;
SocketError errorCode = SocketPal.CreateSocket(_addressFamily, _socketType, _protocolType, out _handle);
SocketError errorCode = SocketPal.CreateSocket(_addressFamily, _socketType, _protocolType, out SafeSocketHandle newHandle);
Volatile.Write(ref _handle, newHandle);
oldHandle.TransferTrackedState(_handle);
oldHandle.Dispose();

if (errorCode != SocketError.Success)
{
return errorCode;
}

if (Volatile.Read(ref _disposed) != 0)
{
_handle.Dispose();
throw new ObjectDisposedException(GetType().FullName);
}

// And put back the copied settings. For DualMode, we use the value stored in the _handle
// rather than querying the socket itself, as on Unix stacks binding a dual-mode socket to
// an IPv6 address may cause the IPv6Only setting to revert to true.
Expand Down

0 comments on commit c092a76

Please sign in to comment.