|
|
|
@ -33,8 +33,11 @@ public class TcpServer<TH, TD, TE> : IDisposable where TH : IChannelHandler
|
|
|
|
|
|
|
|
|
|
public LogLevel? LogLevel { get; set; }
|
|
|
|
|
|
|
|
|
|
public Action? ChannelInActiveAction { get; set; }
|
|
|
|
|
|
|
|
|
|
public TcpServer()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (LogLevel != null)
|
|
|
|
|
{
|
|
|
|
|
InternalLoggerFactory.DefaultFactory.AddProvider(new Log4NetProvider());
|
|
|
|
@ -49,12 +52,12 @@ public class TcpServer<TH, TD, TE> : IDisposable where TH : IChannelHandler
|
|
|
|
|
.Handler(new LoggingHandler())
|
|
|
|
|
.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
|
|
|
|
|
{
|
|
|
|
|
var serverListenerHandler = new ServerListenerHandler<TH, TD, TE>();
|
|
|
|
|
var pipeline = channel.Pipeline;
|
|
|
|
|
if (LogLevel != null)
|
|
|
|
|
var serverListenerHandler = new ServerListenerHandler<TH, TD, TE>
|
|
|
|
|
{
|
|
|
|
|
pipeline.AddLast(new LoggingHandler(LogLevel.Value));
|
|
|
|
|
}
|
|
|
|
|
ChannelInActiveAction = ChannelInActiveAction
|
|
|
|
|
};
|
|
|
|
|
var pipeline = channel.Pipeline;
|
|
|
|
|
pipeline.AddLast(new LoggingHandler());
|
|
|
|
|
pipeline.AddLast(serverListenerHandler);
|
|
|
|
|
pipeline.AddLast(new IdleStateHandler(0, 0, 180)); //检测空闲连接
|
|
|
|
|
//业务handler ,这里是实际处理业务的Handler
|
|
|
|
|