Esempio n. 1
0
        private async Task <Http2Frame> ReceiveFrameAsync(PipeReader reader)
        {
            var frame = new Http2Frame();

            while (true)
            {
                var result = await reader.ReadAsync();

                var buffer   = result.Buffer;
                var consumed = buffer.Start;
                var examined = buffer.Start;

                try
                {
                    if (Http2FrameReader.ReadFrame(buffer, frame, 16_384, out var framePayload))
                    {
                        consumed = examined = framePayload.End;
                        return(frame);
                    }
                    else
                    {
                        examined = buffer.End;
                    }

                    if (result.IsCompleted)
                    {
                        throw new IOException("The reader completed without returning a frame.");
                    }
                }
Esempio n. 2
0
        private async Task <Http2Frame> ReceiveFrameAsync(PipeReader reader)
        {
            var frame = new Http2Frame();

            while (true)
            {
                var result = await reader.ReadAsync();

                var buffer   = result.Buffer;
                var consumed = buffer.Start;
                var examined = buffer.End;

                if (buffer.IsEmpty && result.IsCompleted)
                {
                    throw new IOException("The reader completed without returning a frame.");
                }

                try
                {
                    // Assert.True(buffer.Length > 0);

                    if (Http2FrameReader.ReadFrame(buffer, frame, 16_384, out consumed, out examined))
                    {
                        return(frame);
                    }
                }
                finally
                {
                    reader.AdvanceTo(consumed, examined);
                }
            }
        }
Esempio n. 3
0
        protected async Task <Http2Frame> ReceiveFrameAsync(uint maxFrameSize = Http2PeerSettings.DefaultMaxFrameSize)
        {
            var frame = new Http2Frame(maxFrameSize);

            while (true)
            {
                var result = await _pair.Application.Input.ReadAsync().AsTask().DefaultTimeout();

                var buffer   = result.Buffer;
                var consumed = buffer.Start;
                var examined = buffer.End;

                try
                {
                    Assert.True(buffer.Length > 0);

                    if (Http2FrameReader.ReadFrame(buffer, frame, maxFrameSize, out consumed, out examined))
                    {
                        return(frame);
                    }

                    if (result.IsCompleted)
                    {
                        throw new IOException("The reader completed without returning a frame.");
                    }
                }
                finally
                {
                    _pair.Application.Input.AdvanceTo(consumed, examined);
                }
            }
        }
Esempio n. 4
0
        private async Task <Http2Frame> ReceiveFrameAsync(PipeReader reader)
        {
            var frame = new Http2Frame(Http2PeerSettings.MinAllowedMaxFrameSize);

            while (true)
            {
                var result = await reader.ReadAsync();

                var buffer   = result.Buffer;
                var consumed = buffer.Start;
                var examined = buffer.End;

                try
                {
                    if (Http2FrameReader.ReadFrame(buffer, frame, 16_384, out consumed, out examined))
                    {
                        return(frame);
                    }

                    if (result.IsCompleted)
                    {
                        throw new IOException("The reader completed without returning a frame.");
                    }
                }
                finally
                {
                    reader.AdvanceTo(consumed, examined);
                }
            }
        }