session管理,注册的时候把session放到channel的属性里

master
smartwyy 6 months ago
parent cc308f360a
commit 5942a624c2

@ -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);
}

@ -12,12 +12,13 @@ public class SessionMgr
private static readonly ConcurrentDictionary<string, IoSession> Dictionary =
new ConcurrentDictionary<string, IoSession>();
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)

Loading…
Cancel
Save