public static unsafe bool TryCompleteConnect(SafeCloseSocket socket, int socketAddressLen, out SocketError errorCode)
{
Interop.Error socketError;
Interop.Error err;
try
{
err = Interop.Sys.GetSocketErrorOption(socket, &socketError);
}
catch (ObjectDisposedException)
{
// The socket was closed, or is closing.
errorCode = SocketError.OperationAborted;
return true;
}
if (err != Interop.Error.SUCCESS)
{
Debug.Assert(err == Interop.Error.EBADF, $"Unexpected err: {err}");
errorCode = SocketError.SocketError;
return true;
}
if (socketError == Interop.Error.SUCCESS)
{
errorCode = SocketError.Success;
return true;
}
else if (socketError == Interop.Error.EINPROGRESS)
{
errorCode = SocketError.Success;
return false;
}
errorCode = GetSocketErrorForErrorCode(socketError);
return true;
}