private async Task InternalClose(bool shallNotifyUserSide) { if (Interlocked.Exchange(ref _state, _disposed) == _disposed) { return; } Shutdown(); if (shallNotifyUserSide) { _log.DebugFormat("Session closed for [{0}] on [{1}] in dispatcher [{2}] with session count [{3}].", this.RemoteEndPoint, DateTime.UtcNow.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff"), _module.GetType().Name, this.Server.SessionCount - 1); try { await _module.OnSessionClosed(this); } catch (Exception ex) { await HandleUserSideError(ex); } } Clean(); }
private async Task Close() { if (Interlocked.Exchange(ref _state, _disposed) == _disposed) { return; } try { if (_keepAliveTracker != null) { _keepAliveTracker.Dispose(); } if (_keepAliveTimeoutTimer != null) { _keepAliveTimeoutTimer.Dispose(); } if (_closingTimeoutTimer != null) { _closingTimeoutTimer.Dispose(); } if (_stream != null) { _stream.Dispose(); _stream = null; } if (_tcpClient != null && _tcpClient.Connected) { _tcpClient.Dispose(); _tcpClient = null; } } catch (Exception) { } if (_receiveBuffer != null) { _bufferManager.ReturnBuffer(_receiveBuffer); } if (_sessionBuffer != null) { _bufferManager.ReturnBuffer(_sessionBuffer); } _log.DebugFormat("Session closed for [{0}] on [{1}] in dispatcher [{2}] with session count [{3}].", this.RemoteEndPoint, DateTime.UtcNow.ToString(@"yyyy-MM-dd HH:mm:ss.fffffff"), _module.GetType().Name, this.Server.SessionCount - 1); try { await _module.OnSessionClosed(this); } catch (Exception ex) { HandleUserSideError(ex); } }