Esempio n. 1
0
        /// <summary>
        /// 释放Session关闭事件
        /// </summary>
        /// <param name="session"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        protected virtual async ValueTask FireSessionClosedEvent(AppSession session, CloseReason reason)
        {
            if (session is IHandshakeRequiredSession handshakeSession)
            {
                if (!handshakeSession.Handshaked)
                {
                    return;
                }
            }

            _logger.LogInformation($"The session disconnected: {session.SessionID} ({reason})");

            try
            {
                Interlocked.Decrement(ref _sessionCount);

                var closeEventArgs = new CloseEventArgs(reason);
                await session.FireSessionClosedAsync(closeEventArgs);
                await OnSessionClosedAsync(session, closeEventArgs);
            }
            catch (Exception exc)
            {
                _logger.LogError(exc, "There is one exception thrown from the event of OnSessionClosed.");
            }
        }
Esempio n. 2
0
        protected virtual async ValueTask FireSessionClosedEvent(AppSession <TSessionData> session)
        {
            if (session is IHandshakeRequiredSession hanshakeSession)
            {
                if (!hanshakeSession.Handshaked)
                {
                    return;
                }
            }

            _logger.Info($"The session disconnected: {session.SessionID}");

            try
            {
                Interlocked.Decrement(ref _sessionCount);
                await session.FireSessionClosedAsync(EventArgs.Empty);
                await OnSessionClosedAsync(session);
            }
            catch (Exception exc)
            {
                _logger.Error($"There is one exception thrown from the event of OnSessionClosed.¡¾{exc.ToString()}¡¿");
            }
        }