From 5942a624c2c65acf5f8674325667d980c5d7e0a5 Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Mon, 13 May 2024 19:54:11 +0800 Subject: [PATCH] =?UTF-8?q?session=E7=AE=A1=E7=90=86=EF=BC=8C=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E7=9A=84=E6=97=B6=E5=80=99=E6=8A=8Asession=E6=94=BE?= =?UTF-8?q?=E5=88=B0channel=E7=9A=84=E5=B1=9E=E6=80=A7=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HybirdFrameworkDriver/TcpServer/ServerListenerHandler.cs | 2 +- HybirdFrameworkDriver/TcpServer/SessionMgr.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/HybirdFrameworkDriver/TcpServer/ServerListenerHandler.cs b/HybirdFrameworkDriver/TcpServer/ServerListenerHandler.cs index 0f5eb06..82d6f06 100644 --- a/HybirdFrameworkDriver/TcpServer/ServerListenerHandler.cs +++ b/HybirdFrameworkDriver/TcpServer/ServerListenerHandler.cs @@ -25,7 +25,7 @@ namespace HybirdFrameworkDriver.TcpServer public override void ChannelActive(IChannelHandlerContext context) { base.ChannelActive(context); - SessionMgr.RegisterSession(context.Channel.Id.ToString(), new IoSession(context.Channel)); + SessionMgr.RegisterSession(context.Channel, new IoSession(context.Channel)); Log.Info("active " + context.Channel); } diff --git a/HybirdFrameworkDriver/TcpServer/SessionMgr.cs b/HybirdFrameworkDriver/TcpServer/SessionMgr.cs index da1a56f..6bf8b0e 100644 --- a/HybirdFrameworkDriver/TcpServer/SessionMgr.cs +++ b/HybirdFrameworkDriver/TcpServer/SessionMgr.cs @@ -12,12 +12,13 @@ public class SessionMgr private static readonly ConcurrentDictionary Dictionary = new ConcurrentDictionary(); - public static void RegisterSession(string key, IoSession ioSession) + public static void RegisterSession(IChannel channel, IoSession ioSession) { - ioSession.Key = key; + ioSession.Key = channel.Id.ToString(); IoSession? session; Dictionary.Remove(ioSession.Key, out session); - Dictionary.AddOrUpdate(key, ioSession, (k, oldSession) => ioSession); + ChannelUtils.AddChannelSession(channel, ioSession); + Dictionary.AddOrUpdate(channel.Id.ToString(), ioSession, (k, oldSession) => ioSession); } public static void UnregisterSession(IChannel channel)