public async Task RunAsync(int port, int threadCount)
        {
            var lifetime = new ApplicationLifetime(NullLoggerFactory.Instance.CreateLogger <ApplicationLifetime>());

            Console.CancelKeyPress += (sender, e) => lifetime.StopApplication();

            var libuvOptions = new LibuvTransportOptions
            {
                ThreadCount = threadCount
            };
            var libuvTransport = new LibuvTransportFactory(
                Options.Create(libuvOptions),
                lifetime,
                NullLoggerFactory.Instance);

            var binding = new IPEndPointInformation(new System.Net.IPEndPoint(System.Net.IPAddress.Any, port));

            var transport = libuvTransport.Create(binding, this);
            await transport.BindAsync();

            Console.WriteLine($"Server (raw with headers) listening on http://*:{port} with {libuvOptions.ThreadCount} thread(s)");

            lifetime.ApplicationStopping.WaitHandle.WaitOne();

            await transport.UnbindAsync();

            await transport.StopAsync();
        }
コード例 #2
0
        public async Task RunAsync(int port, int threadCount)
        {
            var lifetime = new ApplicationLifetime(NullLoggerFactory.Instance.CreateLogger <ApplicationLifetime>());

            Console.CancelKeyPress += (sender, e) => lifetime.StopApplication();

            var libuvOptions = new LibuvTransportOptions
            {
                ThreadCount = threadCount
            };
            var libuvTransport = new LibuvTransportFactory(
                Options.Create(libuvOptions),
                lifetime,
                NullLoggerFactory.Instance);

            var serverOptions = new KestrelServerOptions();

            serverOptions.Listen(IPAddress.Any, port);

            var server = new KestrelServer(Options.Create(serverOptions),
                                           libuvTransport,
                                           NullLoggerFactory.Instance);

            await server.StartAsync(this, CancellationToken.None);

            Console.WriteLine($"Server listening on http://*:{port} with {libuvOptions.ThreadCount} thread(s)");

            lifetime.ApplicationStopping.WaitHandle.WaitOne();

            await server.StopAsync(CancellationToken.None);
        }
コード例 #3
0
        public void SetThreadCountUsingProcessorCount()
        {
            // Ideally we'd mock Environment.ProcessorCount to test edge cases.
            var expected = Clamp(Environment.ProcessorCount >> 1, 1, 16);

            var information = new LibuvTransportOptions();

            Assert.Equal(expected, information.ThreadCount);
        }
コード例 #4
0
        public TestLibuvTransportContext()
        {
            var logger = new TestApplicationErrorLogger();

            AppLifetime = new LifetimeNotImplemented();
            Log         = new LibuvTrace(logger);
            Options     = new LibuvTransportOptions {
                ThreadCount = 1
            };
        }
コード例 #5
0
        public void StartWithNonPositiveThreadCountThrows(int threadCount)
        {
            var options = new LibuvTransportOptions {
                ThreadCount = threadCount
            };

            var exception = Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                        new LibuvTransportFactory(Options.Create(options), new LifetimeNotImplemented(), Mock.Of <ILoggerFactory>()));

            Assert.Equal("threadCount", exception.ParamName);
        }
コード例 #6
0
        public TestLibuvTransportContext()
        {
            var logger = new TestApplicationErrorLogger();

            AppLifetime = new LifetimeNotImplemented();
            Log         = logger;
#pragma warning disable CS0618
            Options = new LibuvTransportOptions {
                ThreadCount = 1
            };
#pragma warning restore CS0618
        }
コード例 #7
0
        private static ITransportFactory CreateTransport(Args parsedArgs, ApplicationLifetime lifetime)
        {
            if (parsedArgs.Transport == Transport.Libuv)
            {
                var libuvOptions = new LibuvTransportOptions
                {
                    ThreadCount = parsedArgs.ThreadCount
                };

                Console.WriteLine($"Using {nameof(Transport.Libuv)} transport configured with {libuvOptions.ThreadCount} threads.");

                return(new LibuvTransportFactory(
                           Options.Create(libuvOptions),
                           lifetime,
                           NullLoggerFactory.Instance));
            }
            if (parsedArgs.Transport == Transport.Sockets)
            {
                // TODO: Add the sockets transport
            }

            return(null);
        }