Esempio n. 1
0
        internal SocketConnection(Socket socket,
                                  MemoryPool <byte> memoryPool,
                                  PipeScheduler transportScheduler,
                                  ISocketsTrace trace,
                                  SocketSenderPool socketSenderPool,
                                  PipeOptions inputOptions,
                                  PipeOptions outputOptions,
                                  bool waitForData = true)
        {
            Debug.Assert(socket != null);
            Debug.Assert(memoryPool != null);
            Debug.Assert(trace != null);

            _socket           = socket;
            MemoryPool        = memoryPool;
            _trace            = trace;
            _waitForData      = waitForData;
            _socketSenderPool = socketSenderPool;

            LocalEndPoint  = _socket.LocalEndPoint;
            RemoteEndPoint = _socket.RemoteEndPoint;

            ConnectionClosed = _connectionClosedTokenSource.Token;

            // 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 = OperatingSystem.IsWindows() ? transportScheduler : PipeScheduler.Inline;

            _receiver = new SocketReceiver(awaiterScheduler);

            var pair = DuplexPipe.CreateConnectionPair(inputOptions, outputOptions);

            _originalTransport = pair.Transport;
            Application        = pair.Application;

            Transport = new SocketDuplexPipe(this);

            InitializeFeatures();
        }