public void Shutdown(SocketShutdown how)
{
if (NetEventSource.IsEnabled) NetEventSource.Enter(this, how);
if (CleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"how:{how}");
// This can throw ObjectDisposedException.
SocketError errorCode = SocketPal.Shutdown(_handle, _isConnected, _isDisconnected, how);
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Interop.Winsock.shutdown returns errorCode:{errorCode}");
// Skip good cases: success, socket already closed.
if (errorCode != SocketError.Success && errorCode != SocketError.NotSocket)
{
// Update the internal state of this socket according to the error before throwing.
SocketException socketException = new SocketException((int)errorCode);
UpdateStatusAfterSocketError(socketException);
if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
throw socketException;
}
SetToDisconnected();
InternalSetBlocking(_willBlockInternal);
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}