Ejemplo n.º 1
0
        protected async Task <IChannel> BootStrapChannelAsync(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                              IPAddress address,
                                                              int port)
        {
            var channelHandler = new ServerChannelInitializerBase <IChannel>(HandlerGenerationFunction, handlerEventLoopGroupFactory);

            return(await new Bootstrap()
                   .Group(handlerEventLoopGroupFactory.GetOrCreateSocketIoEventLoopGroup())
                   .ChannelFactory(() => new SocketDatagramChannel(AddressFamily.InterNetwork))
                   .Option(ChannelOption.SoBroadcast, true)
                   .Handler(new LoggingHandler(LogLevel.DEBUG))
                   .Handler(channelHandler)
                   .BindAsync(address, port)
                   .ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        public async Task Can_Dispose_All_Event_Loops()
        {
            _eventFactory = new TcpClientEventLoopGroupFactory(_eventLoopGroupFactoryConfiguration);
            IEventLoopGroup[] eventLoops =
            {
                _eventFactory.GetOrCreateHandlerWorkerEventLoopGroup(),
                _eventFactory.GetOrCreateSocketIoEventLoopGroup()
            };

            _eventFactory.Dispose();

            while (!eventLoops.All(x => x.IsShutdown))
            {
                await Task.Delay(100).ConfigureAwait(false);
            }

            eventLoops.ToList().ForEach(eventLoop => eventLoop.IsShutdown.Should().BeTrue());
        }
Ejemplo n.º 3
0
        protected async Task <IChannel> BootstrapAsync(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                       IPAddress targetAddress,
                                                       int targetPort,
                                                       X509Certificate2 certificate)
        {
            var supervisorLoopGroup = ((ITcpServerEventLoopGroupFactory)handlerEventLoopGroupFactory)
                                      .GetOrCreateSupervisorEventLoopGroup();
            var channelHandler = new ServerChannelInitializerBase <IChannel>(HandlerGenerationFunction, handlerEventLoopGroupFactory, certificate);

            return(await new ServerBootstrap()
                   .Group(handlerEventLoopGroupFactory.GetOrCreateSocketIoEventLoopGroup(), supervisorLoopGroup)
                   .ChannelFactory(() => new TcpServerSocketChannel())
                   .Option(ChannelOption.SoBacklog, _backLogValue)
                   .Handler(new LoggingHandler(LogLevel.DEBUG))
                   .ChildHandler(channelHandler)
                   .BindAsync(targetAddress, targetPort)
                   .ConfigureAwait(false));
        }
Ejemplo n.º 4
0
        protected async Task <IChannel> Bootstrap(IEventLoopGroupFactory handlerEventLoopGroupFactory,
                                                  IPAddress targetAddress,
                                                  int targetPort,
                                                  X509Certificate2 certificate = null)
        {
            var channelHandler = new ClientChannelInitializerBase <ISocketChannel>(HandlerGenerationFunction,
                                                                                   handlerEventLoopGroupFactory,
                                                                                   targetAddress,
                                                                                   certificate);

            return(await new Bootstrap()
                   .Group(handlerEventLoopGroupFactory.GetOrCreateSocketIoEventLoopGroup())
                   .ChannelFactory(() => new TcpSocketChannel())
                   .Option(ChannelOption.SoBacklog, _backLogValue)
                   .Handler(new LoggingHandler(LogLevel.DEBUG))
                   .Handler(channelHandler)
                   .ConnectAsync(targetAddress, targetPort)
                   .ConfigureAwait(false));
        }
Ejemplo n.º 5
0
 public void Can_Spawn_Correct_Amount_Of_Tcp_Client_Event_Loops()
 {
     _eventFactory = new TcpClientEventLoopGroupFactory(_eventLoopGroupFactoryConfiguration);
     AssertEventLoopSize(_eventFactory.GetOrCreateHandlerWorkerEventLoopGroup(), ExpectedTcpClientThreads);
     AssertEventLoopSize(_eventFactory.GetOrCreateSocketIoEventLoopGroup(), ExpectedDefaultEventLoopThreadCount);
 }