System.Net.Sockets.Socket.InternalShutdown C# (CSharp) Method

InternalShutdown() private method

private InternalShutdown ( SocketShutdown how ) : void
how SocketShutdown
return void
        internal void InternalShutdown(SocketShutdown how)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, $"how:{how}");

            if (CleanedUp || _handle.IsInvalid)
            {
                return;
            }

            try
            {
                SocketPal.Shutdown(_handle, _isConnected, _isDisconnected, how);
            }
            catch (ObjectDisposedException) { }
        }

Usage Example

示例#1
0
        // Disposes the Tcp connection.
        protected virtual void Dispose(bool disposing)
        {
            if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0)
            {
                if (disposing)
                {
                    IDisposable?dataStream = _dataStream;
                    if (dataStream != null)
                    {
                        dataStream.Dispose();
                    }
                    else
                    {
                        // If the NetworkStream wasn't created, the Socket might
                        // still be there and needs to be closed. In the case in which
                        // we are bound to a local IPEndPoint this will remove the
                        // binding and free up the IPEndPoint for later uses.
                        Socket chkClientSocket = Volatile.Read(ref _clientSocket);
                        if (chkClientSocket != null)
                        {
                            try
                            {
                                chkClientSocket.InternalShutdown(SocketShutdown.Both);
                            }
                            finally
                            {
                                chkClientSocket.Close();
                            }
                        }
                    }

                    GC.SuppressFinalize(this);
                }
            }
        }
All Usage Examples Of System.Net.Sockets.Socket::InternalShutdown