Exemplo n.º 1
0
        private async Task Close(bool shallNotifyUserSide)
        {
            if (Interlocked.Exchange(ref _state, _closed) == _closed)
            {
                return;
            }

            Clean();

            if (shallNotifyUserSide)
            {
                _log.DebugFormat("Disconnected from server [{0}] with dispatcher [{1}] on [{2}].",
                                 this.RemoteEndPoint,
                                 _dispatcher.GetType().Name,
                                 DateTime.UtcNow.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff"));
                try
                {
                    await _dispatcher.OnServerDisconnected(this);
                }
                catch (Exception ex)
                {
                    HandleUserSideError(ex);
                }
            }
        }
Exemplo n.º 2
0
        private async Task Close(bool shallNotifyUserSide)
        {
            if (Interlocked.Exchange(ref _state, _disposed) == _disposed)
            {
                return;
            }

            try
            {
                if (_stream != null)
                {
                    _stream.Dispose();
                    _stream = null;
                }
                if (_tcpClient != null && _tcpClient.Connected)
                {
                    _tcpClient.Dispose();
                    _tcpClient = null;
                }
            }
            catch (Exception) { }

            if (_receiveBuffer != null)
            {
                _bufferManager.ReturnBuffer(_receiveBuffer);
            }
            _receiveBufferOffset = 0;

            if (shallNotifyUserSide)
            {
                _log.DebugFormat("Disconnected from server [{0}] with dispatcher [{1}] on [{2}].",
                                 this.RemoteEndPoint,
                                 _dispatcher.GetType().Name,
                                 DateTime.UtcNow.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff"));
                try
                {
                    await _dispatcher.OnServerDisconnected(this);
                }
                catch (Exception ex)
                {
                    HandleUserSideError(ex);
                }
            }
        }