Exemple #1
0
        internal UdpConnection(Socket socket,
                               MemoryPool <byte> memoryPool,
                               PipeScheduler scheduler,
                               IUdpConfiguration udpConfiguration,
                               ILogger logger,
                               HandlerMapper handlerMapper)
        {
            Debug.Assert(socket != null);
            Debug.Assert(memoryPool != null);
            Debug.Assert(logger != null);
            Debug.Assert(handlerMapper != null);

            _socket           = socket;
            MemoryPool        = memoryPool;
            Scheduler         = scheduler;
            _logger           = logger;
            _handlerMapper    = handlerMapper;
            _udpConfiguration = udpConfiguration;

            // On *nix platforms, Sockets already dispatches to the ThreadPool.
            // Yes, the IOQueues are still used for the PipeSchedulers. This is intentional.
            // https://github.com/aspnet/KestrelHttpServer/issues/2573
            var awaiterScheduler = IsWindows ? Scheduler : PipeScheduler.Inline;

            _pipe = new Pipe(new PipeOptions(MemoryPool, awaiterScheduler, awaiterScheduler, useSynchronizationContext: false));

            _receiver = new UdpReceiver(_socket, awaiterScheduler);
        }
Exemple #2
0
        public UdpSender(IUdpConfiguration configuration, IPAddress address)
        {
            _configuration = configuration;
            Address        = address;


            var endpoint = new IPEndPoint(Address, _configuration.SendPort);

            _client = new UdpClient();
            _client.Client.SendBufferSize = _configuration.SendBufferSize;
            _client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            _client.Connect(endpoint);
        }
Exemple #3
0
        public UdpTransport(
            IHostApplicationLifetime applicationLifetime,
            IUdpConfiguration udpConfiguration,
            HandlerMapper handlerMapper,
            ILogger <UdpTransport> logger)
        {
            Debug.Assert(applicationLifetime != null);
            Debug.Assert(udpConfiguration != null);
            Debug.Assert(handlerMapper != null);
            Debug.Assert(logger != null);

            _udpConfiguration = udpConfiguration;
            _appLifetime      = applicationLifetime;
            _handlerMapper    = handlerMapper;
            _logger           = logger;

            _memoryPool = Extensions.GetMemoryPoolFactory();

            var configuration = _udpConfiguration.ThreadExecution;

            if (udpConfiguration.IOQueueCount <= 0)
            {
                configuration = HandlerThreadExecution.ThreadPool;
            }

            switch (configuration)
            {
            case HandlerThreadExecution.Inline:
                _numSchedulers = ThreadPoolSchedulerArray_Inline.Length;
                _schedulers    = ThreadPoolSchedulerArray_Inline;
                break;

            case HandlerThreadExecution.ThreadPool:
                _numSchedulers = ThreadPoolSchedulerArray_Pool.Length;
                _schedulers    = ThreadPoolSchedulerArray_Pool;
                break;

            case HandlerThreadExecution.Dedicated:
                _numSchedulers = _udpConfiguration.IOQueueCount;
                _schedulers    = new IOQueue[_numSchedulers];

                for (var i = 0; i < _numSchedulers; i++)
                {
                    _schedulers[i] = new IOQueue();
                }
                break;
            }
        }
Exemple #4
0
        public UdpSenderFactory(IUdpConfiguration configuration)
        {
            _configuration = configuration;

            SenderCache = new MemoryCache(new MemoryCacheOptions());
        }