Exemplo n.º 1
0
        public void Close()
        {
            if (Interlocked.Exchange(ref _state, _disposed) == _disposed)
            {
                return;
            }

            Clean();

            try
            {
                _server.RaiseClientDisconnected(this);
            }
            catch (Exception ex)
            {
                HandleUserSideError(ex);
            }
        }
Exemplo n.º 2
0
        public void Close()
        {
            lock (_opsLock)
            {
                if (!_closed)
                {
                    _closed = true;

                    try
                    {
                        if (_stream != null)
                        {
                            _stream.Close();
                            _stream = null;
                        }
                        if (_tcpClient != null && _tcpClient.Connected)
                        {
                            _tcpClient.Close();
                            _tcpClient = null;
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error(string.Format("Session [{0}] exception occurred, [{1}].", this, ex.Message), ex);
                    }
                    finally
                    {
                        _bufferManager.ReturnBuffer(_receiveBuffer);
                        _receiveBufferOffset = 0;
                    }

                    try
                    {
                        _server.RaiseClientDisconnected(this);
                    }
                    catch (Exception ex)
                    {
                        HandleUserSideError(ex);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void Close(bool shallNotifyUserSide)
        {
            if (Interlocked.Exchange(ref _state, _disposed) == _disposed)
            {
                return;
            }

            Shutdown();

            if (shallNotifyUserSide)
            {
                try
                {
                    _server.RaiseClientDisconnected(this);
                }
                catch (Exception ex) // catch all exceptions from out-side
                {
                    HandleUserSideError(ex);
                }
            }

            Clean();
        }