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.
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using DotNetty.Transport.Channels;
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
|
|
namespace HybirdFrameworkDriver.Session;
|
|
|
|
|
|
|
|
|
|
public class IoSession
|
|
|
|
|
{
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(IoSession));
|
|
|
|
|
|
|
|
|
|
public IoSession(IChannel channel)
|
|
|
|
|
{
|
|
|
|
|
Channel = channel;
|
|
|
|
|
IpAddr = ChannelUtils.GetIp(channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IChannel Channel { get; }
|
|
|
|
|
private string IpAddr { get; }
|
|
|
|
|
public string Key { get; set; }
|
|
|
|
|
|
|
|
|
|
private bool Reconnected { get; set; }
|
|
|
|
|
|
|
|
|
|
//业务数据
|
|
|
|
|
public ConcurrentDictionary<string, object> BusinessMap { get; } = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Send(Object buffer)
|
|
|
|
|
{
|
|
|
|
|
Channel.WriteAndFlushAsync(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsClosed()
|
|
|
|
|
{
|
|
|
|
|
return !Channel.Open || !Channel.Active;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
Channel?.CloseAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|