Exemple #1
0
        public void Disconnect()
        {
            if (IsDisposed)
            {
                return;
            }
            IsDisposed = true;

            if (_socket == null)
            {
                return;
            }
            Flush();

            try
            {
                _socket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            _socket.Close();

            if (_recvBuffer != null)
            {
                lock (_pool)
                {
                    _pool.AddFreeSegment(_recvBuffer);
                }
            }

            if (_incompletePacketBuffer != null)
            {
                lock (_pool)
                {
                    _pool.AddFreeSegment(_incompletePacketBuffer);
                }
            }

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _socket        = null;
            _recvEventArgs = null;
            _sendEventArgs = null;

            lock (_sendQueue)
            {
                if (!_sendQueue.IsEmpty)
                {
                    _sendQueue.Clear();
                }
            }

            _circularBuffer = null;
            Disconnected.Raise();
        }
Exemple #2
0
        private void Disconnect(SocketError error)
        {
            if (IsDisposed)
            {
                return;
            }

            IsDisposed = true;

            if (_socket == null)
            {
                return;
            }

            Flush();

            try
            {
                _socket.Shutdown(SocketShutdown.Both);
            }
            catch
            {
            }

            _socket.Close();

            _incompletePacketBuffer = null;
            _incompletePacketLength = 0;
            _recvBuffer             = null;
            _isCompressionEnabled   = false;
            _socket        = null;
            _recvEventArgs = null;
            _sendEventArgs = null;

            lock (_sendQueue)
            {
                if (!_sendQueue.IsEmpty)
                {
                    _sendQueue.Clear();
                }
            }

            _circularBuffer = null;
            Disconnected.Raise(error);
            Statistics.Reset();
        }