예제 #1
0
        public async override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
        {
            if (exception is SocketException)
            {
                LogsManager.Error(exception, $"Socket exception. Local={context.GetLocalNetString()}, Remote={context.GetRemoteNetString()}, ExceptionMessage={exception.Message}");
                await socketExceptionHandler?.Invoke();
            }
            else
            {
                LogsManager.Error(exception, $"Unhandle exception. Local={context.GetLocalNetString()}, Remote={context.GetRemoteNetString()}, ExceptionMessage={exception.Message}");
                await context.CloseAsync();

                LogsManager.Info($"Channel closed because has an unhandle exception. Local={context.GetLocalNetString()}, Remote={context.GetRemoteNetString()}");
                context.FireExceptionCaught(exception);
            }
        }
예제 #2
0
        public async Task RunAsync(int threadCount, CancellationToken cancellationToken, RecieveServiceRequestDelegate recieveServiceRequest)
        {
            Contract.Requires(threadCount > 0);
            try
            {
                LogsManager.Info("通用服务开始启动!");
                this.parentEventLoopGroup = new MultithreadEventLoopGroup(1);
                this.eventLoopGroup       = new MultithreadEventLoopGroup(threadCount);
                ServerBootstrap bootstrap = this.SetupBootstrap(recieveServiceRequest);

                this.serverChannel = await bootstrap.BindAsync(port);

                cancellationToken.Register(this.CloseAsync);
                LogsManager.Info("通用服务成功启动!");
            }
            catch (Exception ex)
            {
                LogsManager.Error("通用服务启动失败");
                this.CloseAsync();
            }
        }
예제 #3
0
 public override void ChannelUnregistered(IChannelHandlerContext context)
 {
     LogsManager.Info($"Channel unregistered. Local={context.GetLocalNetString()}, Remote={context.GetRemoteNetString()}");
     base.ChannelUnregistered(context);
 }
예제 #4
0
 public override void ChannelInactive(IChannelHandlerContext context)
 {
     LogsManager.Info($"Channel inactived. Local={context.GetLocalNetString()}, Remote={context.GetRemoteNetString()}");
     base.ChannelInactive(context);
 }