public ScheduleTask(IChannelManager channelManager, Ukcp ukcp, IScheduleThread scheduleThread) { _imessageExecutor = ukcp.IMessageExecutor; _channelManager = channelManager; _ukcp = ukcp; _scheduleThread = scheduleThread; }
public ServerChannelHandler(IChannelManager channelManager, ChannelConfig channelConfig, IExecutorPool executorPool, KcpListener kcpListener, IScheduleThread scheduleThread) { _channelManager = channelManager; _channelConfig = channelConfig; _executorPool = executorPool; _kcpListener = kcpListener; _scheduleThread = scheduleThread; }
public void init(IExecutorPool executorPool, KcpListener kcpListener, ChannelConfig channelConfig, params int[] ports) { if (channelConfig.UseConvChannel) { int convIndex = 0; if (channelConfig.Crc32Check) { convIndex += Ukcp.HEADER_CRC; } if (channelConfig.FecDataShardCount != 0 && channelConfig.FecParityShardCount != 0) { convIndex += Fec.fecHeaderSizePlus2; } _channelManager = new ServerConvChannelManager(convIndex); } else { _channelManager = new ServerEndPointChannelManager(); } int cpuNum = Environment.ProcessorCount; int bindTimes = cpuNum; _eventLoopGroup = new MultithreadEventLoopGroup(cpuNum); _scheduleThread = new HashedWheelScheduleThread(); _bootstrap = new Bootstrap(); //TODO epoll模型 服务器端怎么支持?得试试成功没有 _bootstrap.Option(ChannelOption.SoReuseport, true); _bootstrap.Option(ChannelOption.SoReuseaddr, true); _bootstrap.Group(_eventLoopGroup); _bootstrap.ChannelFactory(() => new SocketDatagramChannel(AddressFamily.InterNetwork)); _bootstrap.Handler(new ActionChannelInitializer <SocketDatagramChannel>(channel => { var pipeline = channel.Pipeline; pipeline.AddLast(new ServerChannelHandler(_channelManager, channelConfig, executorPool, kcpListener, _scheduleThread)); })); foreach (var port in ports) { // for (int i = 0; i < bindTimes; i++) { var task = Task.Run(() => _bootstrap.BindAsync(port)); task.Wait(); var channel = task.Result; _localAddress.Add(channel); // } } //TODO 如何启动关闭进程的钩子?? }
public void init(ChannelConfig channelConfig, ExecutorPool executorPool, IEventLoopGroup eventLoopGroup) { if (channelConfig.UseConvChannel) { var convIndex = 0; if (channelConfig.Crc32Check) { convIndex += Ukcp.HEADER_CRC; } if (channelConfig.FecDataShardCount != 0 && channelConfig.FecParityShardCount != 0) { convIndex += Fec.fecHeaderSizePlus2; } _channelManager = new ClientConvChannelManager(convIndex); } else { _channelManager = new ClientEndPointChannelManager(); } //初始化线程池 创建一个线程就够了 _executorPool = executorPool; _executorPool.CreateMessageExecutor(); _eventLoopGroup = eventLoopGroup; _scheduleThread = new EventLoopScheduleThread(); bootstrap = new Bootstrap(); bootstrap.Group(_eventLoopGroup); bootstrap.Option(ChannelOption.SoReuseport, false); bootstrap.Option(ChannelOption.SoReuseaddr, true); bootstrap.ChannelFactory(() => new SocketDatagramChannel(AddressFamily.InterNetwork)); bootstrap.Handler(new ActionChannelInitializer <SocketDatagramChannel>(channel => { var pipeline = channel.Pipeline; pipeline.AddLast(new ClientChannelHandler(_channelManager, channelConfig)); })); }