Exemple #1
0
        // For testing
        public LibuvTransport(LibuvFunctions uv, LibuvTransportContext context, IEndPointInformation endPointInformation)
        {
            Libuv            = uv;
            TransportContext = context;

            _endPointInformation = endPointInformation;
        }
        public Transport(IEndPointInformation ipEndPointInformation, IConnectionDispatcher connectionDispatcher, LinuxTransportOptions transportOptions, ILoggerFactory loggerFactory)
        {
            if (connectionDispatcher == null)
            {
                throw new ArgumentNullException(nameof(connectionDispatcher));
            }
            if (transportOptions == null)
            {
                throw new ArgumentException(nameof(transportOptions));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentException(nameof(loggerFactory));
            }
            if (ipEndPointInformation == null)
            {
                throw new ArgumentException(nameof(ipEndPointInformation));
            }

            _endPoint             = ipEndPointInformation;
            _connectionDispatcher = connectionDispatcher;
            _transportOptions     = transportOptions;
            _loggerFactory        = loggerFactory;
            _logger  = loggerFactory.CreateLogger <Transport>();
            _threads = Array.Empty <TransportThread>();
        }
Exemple #3
0
        internal QuicTransport(
            IEndPointInformation endPointInformation,
            IConnectionDispatcher dispatcher,
            IApplicationLifetime applicationLifetime,
            int ioQueueCount,
            ILogger logger)
        {
            _endPointInformation = endPointInformation;
            _dispatcher          = dispatcher;
            _applicationLifetime = applicationLifetime;
            _logger = logger;

            if (ioQueueCount > 0)
            {
                _numSchedulers = ioQueueCount;
                _schedulers    = new IOQueue[_numSchedulers];

                for (var i = 0; i < _numSchedulers; i++)
                {
                    _schedulers[i] = new IOQueue();
                }
            }
            else
            {
                _numSchedulers = ThreadPoolSchedulerArray.Length;
                _schedulers    = ThreadPoolSchedulerArray;
            }
        }
Exemple #4
0
        internal SocketTransport(
            IEndPointInformation endPointInformation,
            IConnectionDispatcher dispatcher,
            IApplicationLifetime applicationLifetime,
            int ioQueueCount,
            ISocketsTrace trace)
        {
            Debug.Assert(endPointInformation != null);
            Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint);
            Debug.Assert(dispatcher != null);
            Debug.Assert(applicationLifetime != null);
            Debug.Assert(trace != null);

            _endPointInformation = endPointInformation;
            _dispatcher          = dispatcher;
            _appLifetime         = applicationLifetime;
            _trace = trace;

            if (ioQueueCount > 0)
            {
                _numSchedulers = ioQueueCount;
                _schedulers    = new IOQueue[_numSchedulers];

                for (var i = 0; i < _numSchedulers; i++)
                {
                    _schedulers[i] = new IOQueue();
                }
            }
            else
            {
                _numSchedulers = ThreadPoolSchedulerArray.Length;
                _schedulers    = ThreadPoolSchedulerArray;
            }
        }
Exemple #5
0
        public SocketTransport(IEndPointInformation endPointInformation,
                               IConnectionDispatcher dispatcher,
                               int listenBacklog,
                               PipeOptions sendOptions,
                               PipeOptions receiveOptions)
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }
            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new InvalidOperationException(nameof(endPointInformation.IPEndPoint));
            }
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }
            if (listenBacklog < 0)
            {
                throw new InvalidOperationException(nameof(listenBacklog));
            }

            _endPointInformation = endPointInformation;
            _dispatcher          = dispatcher;
            _backlog             = listenBacklog;

            _numSchedulers  = 1;
            _cachedPipeOpts = new PipeOptionsPair[] { new PipeOptionsPair(sendOptions, receiveOptions) };
        }
Exemple #6
0
        public async void ConnectAsync(IEndPointInformation endPoint)
        {
            await _connectTcs.Task;

            SetPipe(_connectTcs.Task.Result);
            StartReceiveLoopAsync().FireAndForget();
        }
Exemple #7
0
 public UvTransport(IEndPointInformation endPoint, IConnectionDispatcher dispatcher, int threadCount = 1, ILibuvTrace log = null)
 {
     _endPointInformation = endPoint;
     _dispatcher          = dispatcher;
     _threadCount         = threadCount;
     Log        = log;
     Threads    = new List <UvThread>();
     _listeners = new List <IAsyncDisposable>();
 }
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
        {
            endPointInformation = endPointInformation ?? throw new ArgumentNullException(nameof(endPointInformation));
            dispatcher          = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));

            var transport = new NetMapTransport(endPointInformation.IPEndPoint, _options.InterfaceName, dispatcher);

            return(transport);
        }
Exemple #9
0
 public UvListenerPrimary(UvThread thread, IEndPointInformation endpoint, ILibuvTrace log = null)
     : base(thread, endpoint, log)
 {
     _dispatchPipes = new List <UvPipeHandle>();
     _createdPipes  = new List <UvPipeHandle>();
     _dummyMessage  = new ArraySegment <ArraySegment <byte> >(new[] {
         new ArraySegment <byte>(new byte[] { 1, 2, 3, 4 })
     });
 }
Exemple #10
0
        public UvDuplexPipeClient(IEndPointInformation endPoint)
        {
            _awaitingResponses = new Dictionary <int, TaskCompletionSource <IMemoryOwner <byte> > >();
            _connectTcs        = new TaskCompletionSource <UvConnection>();
            _endPoint          = endPoint;

            _thread = new UvThread(Log);
            _thread.Post(_startConnect, this);
        }
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
        {
            if (ConnectionDispatcher != null)
            {
                throw new InvalidOperationException("InMemoryTransportFactory doesn't support creating multiple endpoints");
            }

            ConnectionDispatcher = dispatcher;

            return(new NoopTransport());
        }
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
        {
            var transportContext = new LibuvTransportContext
            {
                Options              = _baseTransportContext.Options,
                AppLifetime          = _baseTransportContext.AppLifetime,
                Log                  = _baseTransportContext.Log,
                ConnectionDispatcher = dispatcher
            };

            return(new LibuvTransport(transportContext, endPointInformation));
        }
Exemple #13
0
 public Transport(
     IListenerLogger logger,
     InlineSocketsOptions options,
     INetworkProvider networkProvider,
     IEndPointInformation endPointInformation,
     IConnectionDispatcher dispatcher)
 {
     _listener            = new Listener(logger, options, networkProvider);
     _logger              = logger;
     _endPointInformation = endPointInformation;
     _dispatcher          = dispatcher;
 }
Exemple #14
0
        // TODO:这里之前是override,但是因为我需要有个口子可以设定transport,
        // 所以需要从这里传入一个配置项;很杯具的是libuv可不需要Pipeline这个概念,
        // 所以暂时先去掉override让编译可以通过吧。
        public async Task StartAsync(IEndPointInformation endPoint)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(ToString());
            }

            _transport = new UvTransport(endPoint, _dispather, ThreadCount, Log);

            await _transport.BindAsync();

            OnServerStarted(endPoint);
        }
Exemple #15
0
            public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler)
            {
                var connections = new InMemoryConnection[_connectionsPerEndPoint];

                for (var i = 0; i < _connectionsPerEndPoint; i++)
                {
                    connections[i] = new InMemoryConnection();
                }

                _connections.Add(endPointInformation, connections);

                return(new InMemoryTransport(handler, connections));
            }
Exemple #16
0
        public Task StartAsync(
            IEndPointInformation endPointInformation,
            LibuvThread thread)
        {
            EndPointInformation = endPointInformation;
            Thread = thread;

            return(Thread.PostAsync(listener =>
            {
                listener.ListenSocket = listener.CreateListenSocket();
                listener.ListenSocket.Listen(LibuvConstants.ListenBacklog, ConnectionCallback, listener);
            }, this));
        }
Exemple #17
0
        public SocketTransport(IEndPointInformation endPointInformation,
                               IConnectionDispatcher dispatcher,
                               int listenBacklog,
                               int ioQueueCount,
                               MemoryPool <byte> pool = null,
                               ILogger logger         = null)
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }
            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new InvalidOperationException(nameof(endPointInformation.IPEndPoint));
            }
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }
            if (listenBacklog < 0)
            {
                throw new InvalidOperationException(nameof(listenBacklog));
            }

            _endPointInformation = endPointInformation;
            _dispatcher          = dispatcher;
            _backlog             = listenBacklog;
            _pool   = pool;
            _logger = logger ?? NullLoggerFactory.Instance.CreateLogger("NetGear.Core.SocketTransport");
            _trace  = new TraceDebugger(_logger);

            if (ioQueueCount > 0)
            {
                _numSchedulers  = ioQueueCount;
                _cachedPipeOpts = new PipeOptionsPair[_numSchedulers];

                for (var i = 0; i < _numSchedulers; i++)
                {
                    _cachedPipeOpts[i] = new PipeOptionsPair(
                        GetSendPipeOptions(_pool, new IOQueue()),
                        GetReceivePipeOptions(_pool, new IOQueue()));
                }
            }
            else
            {
                _numSchedulers  = 1;
                _cachedPipeOpts = new PipeOptionsPair[] { new PipeOptionsPair(
                                                              GetSendPipeOptions(_pool, new IOQueue()),
                                                              GetReceivePipeOptions(_pool, new IOQueue())) };
            }
        }
Exemple #18
0
        internal SocketTransport(SocketTransportFactory transportFactory, IEndPointInformation endPointInformation, IConnectionHandler handler)
        {
            Debug.Assert(transportFactory != null);
            Debug.Assert(endPointInformation != null);
            Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint);
            Debug.Assert(handler != null);

            _transportFactory    = transportFactory;
            _endPointInformation = endPointInformation;
            _handler             = handler;

            _listenSocket = null;
            _listenTask   = null;
        }
        public async Task RunAsync(ITransportFactory transportFactory, IEndPointInformation endPointInformation, ApplicationLifetime lifetime)
        {
            Console.CancelKeyPress += (sender, e) => lifetime.StopApplication();

            var transport = transportFactory.Create(endPointInformation, this);

            await transport.BindAsync();

            Console.WriteLine($"Server ({nameof(PlainTextRawWithHeadersApplication)}) listening on http://{endPointInformation.IPEndPoint}");

            lifetime.ApplicationStopping.WaitHandle.WaitOne();

            await transport.UnbindAsync();

            await transport.StopAsync();
        }
        internal SocketTransport(
            IEndPointInformation endPointInformation,
            IConnectionHandler handler,
            ISocketsTrace trace)
        {
            Debug.Assert(endPointInformation != null);
            Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint);
            Debug.Assert(handler != null);
            Debug.Assert(trace != null);

            _endPointInformation = endPointInformation;
            _handler             = handler;
            _trace = trace;

            _listenSocket = null;
            _listenTask   = null;
        }
        internal SocketTransport(
            IEndPointInformation endPointInformation,
            IConnectionHandler handler,
            IApplicationLifetime applicationLifetime,
            ISocketsTrace trace)
        {
            Debug.Assert(endPointInformation != null);
            Debug.Assert(endPointInformation.Type == ListenType.IPEndPoint);
            Debug.Assert(handler != null);
            Debug.Assert(applicationLifetime != null);
            Debug.Assert(trace != null);

            _endPointInformation = endPointInformation;
            _handler             = handler;
            _appLifetime         = applicationLifetime;
            _trace = trace;
        }
Exemple #22
0
        private static IPEndPoint CreateEndPointFromIEndPointInformation(IEndPointInformation IEndPointInformation)
        {
            if (IEndPointInformation == null)
            {
                throw new ArgumentNullException(nameof(IEndPointInformation));
            }
            if (IEndPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new NotSupportedException("Only IPEndPoints are supported.");
            }
            if (IEndPointInformation.IPEndPoint == null)
            {
                throw new ArgumentNullException(nameof(IEndPointInformation.IPEndPoint));
            }

            return(IEndPointInformation.IPEndPoint);
        }
Exemple #23
0
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionHandler handler)
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }

            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation));
            }

            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            return(new SocketTransport(endPointInformation, handler, _trace));
        }
        public Task StartAsync(
            string pipeName,
            byte[] pipeMessage,
            IEndPointInformation endPointInformation,
            LibuvThread thread)
        {
            _pipeName    = pipeName;
            _pipeMessage = pipeMessage;
            _buf         = thread.Loop.Libuv.buf_init(_ptr, 4);

            EndPointInformation = endPointInformation;
            Thread       = thread;
            DispatchPipe = new UvPipeHandle(Log);

            var tcs = new TaskCompletionSource <int>(this, TaskCreationOptions.RunContinuationsAsynchronously);

            Thread.Post(StartCallback, tcs);
            return(tcs.Task);
        }
Exemple #25
0
    public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
    {
        if (endPointInformation == null)
        {
            throw new ArgumentNullException(nameof(endPointInformation));
        }

        if (endPointInformation.Type != ListenType.IPEndPoint)
        {
            throw new ArgumentException("OnlyIPEndPointsSupported");
        }

        if (dispatcher == null)
        {
            throw new ArgumentNullException(nameof(dispatcher));
        }

        return(new KestrelStackTransport(this.Server._NullCheck(), endPointInformation, dispatcher, AppLifeTime, Options.IOQueueCount, Trace));
    }
Exemple #26
0
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }

            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation));
            }

            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            return(new SocketTransport(endPointInformation, dispatcher, _appLifetime, _options.IOQueueCount, _trace));
        }
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }

            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new ArgumentException("Only IP endpoint is supported", nameof(endPointInformation));
            }

            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            return(new QuicTransport(endPointInformation, dispatcher, _appLifetime, _options.IOQueueCount, _logger));
        }
Exemple #28
0
#pragma warning disable PUB0001 // Pubternal type in public API
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
#pragma warning restore PUB0001 // Pubternal type in public API
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }

            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new ArgumentException(SocketsStrings.OnlyIPEndPointsSupported, nameof(endPointInformation));
            }

            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            return(new SocketTransport(endPointInformation, dispatcher, _appLifetime, _options.IOQueueCount, _trace, _options.MemoryPoolFactory()));
        }
        public async Task RunAsync(ITransportFactory transportFactory, IEndPointInformation endPointInformation, ApplicationLifetime lifetime)
        {
            Console.CancelKeyPress += (sender, e) => lifetime.StopApplication();

            var serverOptions = new KestrelServerOptions();

            serverOptions.Listen(endPointInformation.IPEndPoint);

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

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

            Console.WriteLine($"Server ({nameof(PlainTextApplication)}) listening on http://{endPointInformation.IPEndPoint}");

            lifetime.ApplicationStopping.WaitHandle.WaitOne();

            await server.StopAsync(CancellationToken.None);
        }
Exemple #30
0
#pragma warning disable PUB0001 // Pubternal type in public API
        public ITransport Create(IEndPointInformation endPointInformation, IConnectionDispatcher dispatcher)
#pragma warning restore PUB0001 // Pubternal type in public API
        {
            if (endPointInformation == null)
            {
                throw new ArgumentNullException(nameof(endPointInformation));
            }

            if (endPointInformation.Type != ListenType.IPEndPoint)
            {
                throw new ArgumentException("Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850", nameof(endPointInformation));
            }

            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            return(new SocketTransport(endPointInformation, dispatcher, _appLifetime, _options.IOQueueCount, _trace, _options.MemoryPoolFactory()));
        }