You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
986 B
36 lines
986 B
using System.Collections.Concurrent;
|
|
using DotNetty.Buffers;
|
|
using DotNetty.Transport.Channels;
|
|
using log4net;
|
|
|
|
namespace HybirdFrameworkServices.Netty;
|
|
|
|
public class SessionMgr
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(SessionMgr));
|
|
|
|
private static readonly ConcurrentDictionary<string, IoSession> Dictionary =
|
|
new ConcurrentDictionary<string, IoSession>();
|
|
|
|
public static void RegisterSession(string key, IoSession ioSession)
|
|
{
|
|
ioSession.Key = key;
|
|
Dictionary.GetOrAdd(key, ioSession);
|
|
}
|
|
|
|
public static void UnregisterSession(IChannel channel)
|
|
{
|
|
IoSession session = ChannelUtils.GetSessionBy(channel);
|
|
IoSession? outSession;
|
|
Dictionary.Remove(session.Key, out outSession);
|
|
session.Close();
|
|
}
|
|
|
|
public static void Broadcast(IByteBuffer buffer)
|
|
{
|
|
foreach (IoSession session in Dictionary.Values)
|
|
{
|
|
session.Send(buffer);
|
|
}
|
|
}
|
|
} |