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.

43 lines
1.1 KiB

using DotNetty.Common.Utilities;
using DotNetty.Transport.Channels;
7 months ago
namespace HybirdFrameworkDriver.Session;
public static class ChannelUtils
{
private static readonly AttributeKey<IoSession> SessionKey = AttributeKey<IoSession>.ValueOf("session");
/**
*
* @param channel
* @param session
* @return
*/
public static void AddChannelSession(IChannel channel, IoSession session)
{
AddAttr(channel, SessionKey, session);
}
public static void AddAttr<T>(IChannel channel, AttributeKey<T> key, T t) where T : class
{
var attribute = channel.GetAttribute(key);
attribute.Set(t);
}
public static T? GetAttr<T>(IChannel channel, AttributeKey<T> key) where T : class
{
var attribute = channel.GetAttribute(key);
return attribute.Get();
}
public static IoSession GetSessionBy(IChannel channel)
{
6 months ago
var sessionAttr = channel.GetAttribute(SessionKey);
return sessionAttr.Get();
}
6 months ago
public static string GetIp(IChannel channel)
{
return channel.RemoteAddress.Serialize().ToString();
}
}