コード例 #1
0
        public async Task ProcessRequestAsync <TContext>(IHttpApplication <TContext> application)
        {
            Exception error = null;

            try
            {
                while (_isClosed == 0)
                {
                    var result = await Input.ReadAsync();

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

                    try
                    {
                        if (!readableBuffer.IsEmpty)
                        {
                            while (Http3FrameReader.TryReadFrame(ref readableBuffer, _incomingFrame, 16 * 1024, out var framePayload))
                            {
                                consumed = examined = framePayload.End;
                                await ProcessHttp3Stream(application, framePayload);
                            }
                        }

                        if (result.IsCompleted)
                        {
                            OnEndStreamReceived();
                            return;
                        }
                    }

                    finally
                    {
                        Input.AdvanceTo(consumed, examined);
                    }
                }
            }
            catch (Http3StreamErrorException ex)
            {
                error = ex;
                Abort(new ConnectionAbortedException(ex.Message, ex), ex.ErrorCode);
            }
            catch (Exception ex)
            {
                error = ex;
                Log.LogWarning(0, ex, "Stream threw an unexpected exception.");
            }
            finally
            {
                var streamError = error as ConnectionAbortedException
                                  ?? new ConnectionAbortedException("The stream has completed.", error);

                Input.Complete();

                await RequestBodyPipe.Writer.CompleteAsync();

                // Make sure application func is completed before completing writer.
                if (_appCompleted != null)
                {
                    await _appCompleted.Task;
                }

                try
                {
                    _frameWriter.Complete();
                }
                catch
                {
                    Abort(streamError, Http3ErrorCode.ProtocolError);
                    throw;
                }
                finally
                {
                    _http3Connection.RemoveStream(_streamIdFeature.StreamId);
                }
            }
        }
コード例 #2
0
        public async Task ProcessRequestAsync <TContext>(IHttpApplication <TContext> application)
        {
            Exception error = null;

            try
            {
                while (_isClosed == 0)
                {
                    var result = await Input.ReadAsync();

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

                    try
                    {
                        if (!readableBuffer.IsEmpty)
                        {
                            while (Http3FrameReader.TryReadFrame(ref readableBuffer, _incomingFrame, 16 * 1024, out var framePayload))
                            {
                                consumed = examined = framePayload.End;
                                await ProcessHttp3Stream(application, framePayload);
                            }
                        }

                        if (result.IsCompleted)
                        {
                            return;
                        }
                    }

                    finally
                    {
                        Input.AdvanceTo(consumed, examined);
                    }
                }
            }
            catch (Exception ex)
            {
                error = ex;
                Log.LogWarning(0, ex, "Stream threw an exception.");
            }
            finally
            {
                var streamError = error as ConnectionAbortedException
                                  ?? new ConnectionAbortedException("The stream has completed.", error);
                try
                {
                    _frameWriter.Complete();
                }
                catch
                {
                    _frameWriter.Abort(streamError);
                    throw;
                }
                finally
                {
                    Input.Complete();
                    _context.Transport.Input.CancelPendingRead();
                    await RequestBodyPipe.Writer.CompleteAsync();
                }
            }
        }