public static SocketError Shutdown(SafeCloseSocket handle, bool isConnected, bool isDisconnected, SocketShutdown how)
{
Interop.Error err = Interop.Sys.Shutdown(handle, how);
if (err == Interop.Error.SUCCESS)
{
return SocketError.Success;
}
// If shutdown returns ENOTCONN and we think that this socket has ever been connected,
// ignore the error. This can happen for TCP connections if the underlying connection
// has reached the CLOSE state. Ignoring the error matches Winsock behavior.
if (err == Interop.Error.ENOTCONN && (isConnected || isDisconnected))
{
return SocketError.Success;
}
return GetSocketErrorForErrorCode(err);
}