Exemple #1
0
 private State GetState(IHttp2Stream stream)
 {
     if (stream is null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stream);
     }
     return(stream.GetProperty <State>(_stateKey));
 }
Exemple #2
0
            private void OnHttp2StreamStateChanged0(IHttp2Stream stream)
            {
                var stream2 = stream.GetProperty <DefaultHttp2FrameStream>(_frameCodec._streamKey);

                if (stream2 is object)
                {
                    _frameCodec.OnHttp2StreamStateChanged(_frameCodec._ctx, stream2);
                }
            }
            public override void OnStreamRemoved(IHttp2Stream stream)
            {
                var compressor = stream.GetProperty <EmbeddedChannel>(_encoder._propertyKey);

                if (compressor is object)
                {
                    _encoder.Cleanup(stream, compressor);
                }
            }
Exemple #4
0
 private bool InternalVisit(IHttp2Stream stream, Func <IHttp2FrameStream, bool> streamVisitor)
 {
     try
     {
         return(streamVisitor(stream.GetProperty <IHttp2FrameStream>(_streamKey)));
     }
     catch (Exception cause)
     {
         OnError(_ctx, false, cause);
         return(false);
     }
 }
Exemple #5
0
 private FlowState GetState(IHttp2Stream stream)
 {
     return(stream.GetProperty <FlowState>(_stateKey));
 }
 /// <summary>
 /// Get the <see cref="IFullHttpMessage"/> associated with <paramref name="stream"/>.
 /// </summary>
 /// <param name="stream">The stream to get the associated state from</param>
 /// <returns>The <see cref="IFullHttpMessage"/> associated with <paramref name="stream"/>.</returns>
 protected IFullHttpMessage GetMessage(IHttp2Stream stream)
 {
     return(stream.GetProperty <IFullHttpMessage>(_messageKey));
 }
Exemple #7
0
 Http2Decompressor Decompressor(IHttp2Stream stream)
 {
     return(stream?.GetProperty <Http2Decompressor>(_propertyKey));
 }
        public override Task WriteDataAsync(IChannelHandlerContext ctx, int streamId, IByteBuffer data, int padding, bool endOfStream, IPromise promise)
        {
            IHttp2Stream    stream  = Connection.Stream(streamId);
            EmbeddedChannel channel = stream?.GetProperty <EmbeddedChannel>(_propertyKey);

            if (channel is null)
            {
                // The compressor may be null if no compatible encoding type was found in this stream's headers
                return(base.WriteDataAsync(ctx, streamId, data, padding, endOfStream, promise));
            }

            try
            {
                // The channel will release the buffer after being written
                _ = channel.WriteOutbound(data);
                var buf = NextReadableBuf(channel);
                if (buf is null)
                {
                    if (endOfStream)
                    {
                        if (channel.Finish())
                        {
                            buf = NextReadableBuf(channel);
                        }
                        return(base.WriteDataAsync(ctx, streamId, buf ?? Unpooled.Empty, padding,
                                                   true, promise));
                    }
                    // END_STREAM is not set and the assumption is data is still forthcoming.
                    promise.Complete();
                    return(promise.Task);
                }

                var tasks = new List <Task>();
                while (true)
                {
                    var nextBuf = NextReadableBuf(channel);
                    var compressedEndOfStream = nextBuf is null && endOfStream;
                    if (compressedEndOfStream && channel.Finish())
                    {
                        nextBuf = NextReadableBuf(channel);
                        compressedEndOfStream = nextBuf is null;
                    }

                    var bufPromise = ctx.NewPromise();
                    tasks.Add(bufPromise.Task);
                    _ = base.WriteDataAsync(ctx, streamId, buf, padding, compressedEndOfStream, bufPromise);

                    if (nextBuf is null)
                    {
                        break;
                    }

                    padding = 0; // Padding is only communicated once on the first iteration
                    buf     = nextBuf;
                }
                Task.WhenAll(tasks).LinkOutcome(promise);
            }
            catch (Exception cause)
            {
                _ = promise.TrySetException(cause);
            }
            finally
            {
                if (endOfStream)
                {
                    Cleanup(stream, channel);
                }
            }

            return(promise.Task);
        }
Exemple #9
0
 IFlowState GetState(IHttp2Stream stream) => stream.GetProperty <IFlowState>(_stateKey);