Esempio n. 1
0
        public Http2FrameWriter(
            PipeWriter outputPipeWriter,
            BaseConnectionContext connectionContext,
            Http2Connection http2Connection,
            OutputFlowControl connectionOutputFlowControl,
            ITimeoutControl timeoutControl,
            MinDataRate?minResponseDataRate,
            string connectionId,
            MemoryPool <byte> memoryPool,
            ServiceContext serviceContext)
        {
            // Allow appending more data to the PipeWriter when a flush is pending.
            _outputWriter                = new ConcurrentPipeWriter(outputPipeWriter, memoryPool, _writeLock);
            _connectionContext           = connectionContext;
            _http2Connection             = http2Connection;
            _connectionOutputFlowControl = connectionOutputFlowControl;
            _connectionId                = connectionId;
            _log                 = serviceContext.Log;
            _timeoutControl      = timeoutControl;
            _minResponseDataRate = minResponseDataRate;
            _flusher             = new TimingPipeFlusher(timeoutControl, serviceContext.Log);
            _flusher.Initialize(_outputWriter);
            _outgoingFrame        = new Http2Frame();
            _headerEncodingBuffer = new byte[_maxFrameSize];

            _scheduleInline = serviceContext.Scheduler == PipeScheduler.Inline;

            _hpackEncoder = new DynamicHPackEncoder(serviceContext.ServerOptions.AllowResponseHeaderCompression);
        }
Esempio n. 2
0
        public Http2OutputProducer(
            int streamId,
            Http2FrameWriter frameWriter,
            StreamOutputFlowControl flowControl,
            MemoryPool <byte> pool,
            Http2Stream stream,
            IKestrelTrace log)
        {
            _streamId    = streamId;
            _frameWriter = frameWriter;
            _flowControl = flowControl;
            _memoryPool  = pool;
            _stream      = stream;
            _log         = log;

            var pipe = CreateDataPipe(pool);

            _pipeWriter = new ConcurrentPipeWriter(pipe.Writer, pool, _dataWriterLock);
            _pipeReader = pipe.Reader;

            // No need to pass in timeoutControl here, since no minDataRates are passed to the TimingPipeFlusher.
            // The minimum output data rate is enforced at the connection level by Http2FrameWriter.
            _flusher = new TimingPipeFlusher(_pipeWriter, timeoutControl: null, log);
            _dataWriteProcessingTask = ProcessDataWrites();
        }
        public async Task IfFlushIsCalledAgainBeforeTheLastFlushCompletedItWaitsForTheLastCall()
        {
            var mockPipeWriter          = new Mock <PipeWriter>();
            var pipeWriterFlushTcsArray = new[] {
                new TaskCompletionSource <FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
                new TaskCompletionSource <FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
                new TaskCompletionSource <FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
            };
            var pipeWriterFlushCallCount = 0;

            mockPipeWriter.Setup(p => p.FlushAsync(CancellationToken.None)).Returns(() =>
            {
                return(new ValueTask <FlushResult>(pipeWriterFlushTcsArray[pipeWriterFlushCallCount++].Task));
            });

            var timingPipeFlusher = new TimingPipeFlusher(mockPipeWriter.Object, null, null);

            var flushTask0 = timingPipeFlusher.FlushAsync();
            var flushTask1 = timingPipeFlusher.FlushAsync();
            var flushTask2 = timingPipeFlusher.FlushAsync();

            Assert.False(flushTask0.IsCompleted);
            Assert.False(flushTask1.IsCompleted);
            Assert.False(flushTask2.IsCompleted);
            Assert.Equal(1, pipeWriterFlushCallCount);

            pipeWriterFlushTcsArray[0].SetResult(default);
        //private int _unflushedBytes;

        public Http3FrameWriter(PipeWriter output, ConnectionContext connectionContext, ITimeoutControl timeoutControl, MinDataRate minResponseDataRate, string connectionId, MemoryPool <byte> memoryPool, IKestrelTrace log)
        {
            _outputWriter        = output;
            _connectionContext   = connectionContext;
            _timeoutControl      = timeoutControl;
            _minResponseDataRate = minResponseDataRate;
            _memoryPool          = memoryPool;
            _log                  = log;
            _outgoingFrame        = new Http3RawFrame();
            _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
            _headerEncodingBuffer = new byte[_maxFrameSize];
        }
 public Http2OutputProducer(
     int streamId,
     Http2FrameWriter frameWriter,
     StreamOutputFlowControl flowControl,
     ITimeoutControl timeoutControl,
     MemoryPool <byte> pool)
 {
     _streamId                = streamId;
     _frameWriter             = frameWriter;
     _flowControl             = flowControl;
     _dataPipe                = CreateDataPipe(pool);
     _flusher                 = new TimingPipeFlusher(_dataPipe.Writer, timeoutControl);
     _dataWriteProcessingTask = ProcessDataWrites();
 }
Esempio n. 6
0
 public Http1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IHttpMinResponseDataRateFeature minResponseDataRateFeature)
 {
     _pipeWriter        = pipeWriter;
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _log = log;
     _minResponseDataRateFeature = minResponseDataRateFeature;
     _flusher = new TimingPipeFlusher(pipeWriter, timeoutControl, log);
 }
Esempio n. 7
0
 public Proto1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IProtoMinResponseDataRateFeature minResponseDataRateFeature,
     MemoryPool <byte> memoryPool)
 {
     _pipeWriter        = pipeWriter;
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _log = log;
     _minResponseDataRateFeature = minResponseDataRateFeature;
     _flusher    = new TimingPipeFlusher(pipeWriter, timeoutControl, log);
     _memoryPool = memoryPool;
 }
Esempio n. 8
0
 public Proto2OutputProducer(
     int streamId,
     Proto2FrameWriter frameWriter,
     StreamOutputFlowControl flowControl,
     ITimeoutControl timeoutControl,
     MemoryPool <byte> pool,
     Proto2Stream stream,
     IKestrelTrace log)
 {
     _streamId                = streamId;
     _frameWriter             = frameWriter;
     _flowControl             = flowControl;
     _stream                  = stream;
     _dataPipe                = CreateDataPipe(pool);
     _flusher                 = new TimingPipeFlusher(_dataPipe.Writer, timeoutControl, log);
     _dataWriteProcessingTask = ProcessDataWrites();
 }
Esempio n. 9
0
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     string connectionId,
     IKestrelTrace log)
 {
     _outputWriter                = outputPipeWriter;
     _connectionContext           = connectionContext;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log                  = log;
     _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl);
     _outgoingFrame        = new Http2Frame();
     _headerEncodingBuffer = new byte[_maxFrameSize];
 }
Esempio n. 10
0
 public Http1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IHttpMinResponseDataRateFeature minResponseDataRateFeature,
     MemoryPool <byte> memoryPool)
 {
     // Allow appending more data to the PipeWriter when a flush is pending.
     _pipeWriter        = new ConcurrentPipeWriter(pipeWriter, memoryPool, _contextLock);
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _log = log;
     _minResponseDataRateFeature = minResponseDataRateFeature;
     _flusher    = new TimingPipeFlusher(_pipeWriter, timeoutControl, log);
     _memoryPool = memoryPool;
 }
Esempio n. 11
0
        public Http3OutputProducer(
            Http3FrameWriter frameWriter,
            MemoryPool <byte> pool,
            Http3Stream stream,
            IKestrelTrace log)
        {
            _frameWriter = frameWriter;
            _memoryPool  = pool;
            _stream      = stream;
            _log         = log;

            var pipe = CreateDataPipe(pool);

            _pipeWriter = pipe.Writer;
            _pipeReader = pipe.Reader;

            _flusher = new TimingPipeFlusher(_pipeWriter, timeoutControl: null, log);
            _dataWriteProcessingTask = ProcessDataWrites();
        }
        public Http2OutputProducer(Http2Stream stream, Http2StreamContext context, StreamOutputFlowControl flowControl)
        {
            _stream      = stream;
            _frameWriter = context.FrameWriter;
            _flowControl = flowControl;
            _memoryPool  = context.MemoryPool;
            _log         = context.ServiceContext.Log;

            _pipe = CreateDataPipe(_memoryPool);

            _pipeWriter = new ConcurrentPipeWriter(_pipe.Writer, _memoryPool, _dataWriterLock);
            _pipeReader = _pipe.Reader;

            // No need to pass in timeoutControl here, since no minDataRates are passed to the TimingPipeFlusher.
            // The minimum output data rate is enforced at the connection level by Http2FrameWriter.
            _flusher = new TimingPipeFlusher(_pipeWriter, timeoutControl: null, _log);

            _dataWriteProcessingTask = ProcessDataWrites();
        }
Esempio n. 13
0
    public Http2OutputProducer(Http2Stream stream, Http2StreamContext context)
    {
        _stream      = stream;
        _frameWriter = context.FrameWriter;
        _memoryPool  = context.MemoryPool;
        _log         = context.ServiceContext.Log;
        var scheduleInline = context.ServiceContext.Scheduler == PipeScheduler.Inline;

        _pipe = CreateDataPipe(_memoryPool, scheduleInline);

        _pipeWriter = new ConcurrentPipeWriter(_pipe.Writer, _memoryPool, _dataWriterLock);
        _pipeReader = _pipe.Reader;

        // No need to pass in timeoutControl here, since no minDataRates are passed to the TimingPipeFlusher.
        // The minimum output data rate is enforced at the connection level by Http2FrameWriter.
        _flusher = new TimingPipeFlusher(timeoutControl: null, _log);
        _flusher.Initialize(_pipeWriter);
        _streamWindow = context.ClientPeerSettings.InitialWindowSize;
    }
Esempio n. 14
0
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     Http2Connection http2Connection,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     MinDataRate minResponseDataRate,
     string connectionId,
     IKestrelTrace log)
 {
     _outputWriter                = outputPipeWriter;
     _connectionContext           = connectionContext;
     _http2Connection             = http2Connection;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log                  = log;
     _timeoutControl       = timeoutControl;
     _minResponseDataRate  = minResponseDataRate;
     _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
     _outgoingFrame        = new Http2Frame();
     _headerEncodingBuffer = new byte[_maxFrameSize];
 }
Esempio n. 15
0
        //private int _unflushedBytes;

        public Http3FrameWriter(PipeWriter output, ConnectionContext connectionContext, ITimeoutControl timeoutControl, MinDataRate?minResponseDataRate, string connectionId, MemoryPool <byte> memoryPool, IKestrelTrace log, IStreamIdFeature streamIdFeature, Http3PeerSettings clientPeerSettings, IHttp3Stream http3Stream)
        {
            _outputWriter        = output;
            _connectionContext   = connectionContext;
            _timeoutControl      = timeoutControl;
            _minResponseDataRate = minResponseDataRate;
            _connectionId        = connectionId;
            _memoryPool          = memoryPool;
            _log                  = log;
            _streamIdFeature      = streamIdFeature;
            _http3Stream          = http3Stream;
            _outgoingFrame        = new Http3RawFrame();
            _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
            _headerEncodingBuffer = new byte[_maxFrameSize];

            // Note that max total header size value doesn't react to settings change during a stream.
            // Unlikely to be a problem in practice:
            // - Settings rarely change after the start of a connection.
            // - Response header size limits are a best-effort requirement in the spec.
            _maxTotalHeaderSize = clientPeerSettings.MaxRequestHeaderFieldSectionSize > int.MaxValue
                ? int.MaxValue
                : (int)clientPeerSettings.MaxRequestHeaderFieldSectionSize;
        }
Esempio n. 16
0
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     Http2Connection http2Connection,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     MinDataRate minResponseDataRate,
     string connectionId,
     MemoryPool <byte> memoryPool,
     IKestrelTrace log)
 {
     // Allow appending more data to the PipeWriter when a flush is pending.
     _outputWriter                = new ConcurrentPipeWriter(outputPipeWriter, memoryPool, _writeLock);
     _connectionContext           = connectionContext;
     _http2Connection             = http2Connection;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log                  = log;
     _timeoutControl       = timeoutControl;
     _minResponseDataRate  = minResponseDataRate;
     _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
     _outgoingFrame        = new Http2Frame();
     _headerEncodingBuffer = new byte[_maxFrameSize];
 }