Exemplo n.º 1
0
            // wait for read to complete, then continue async
            static async ValueTask <(HeaderEnumerator Headers, bool IsHeader, Memory <char> PushBack)> ReadAsync_ContinueAfterReadAsync(HeadersReader <T> self, ValueTask <int> waitFor, CancellationToken cancel)
            {
                var available = await waitFor;

                // handle the in flight task
                if (available == 0)
                {
                    if (self.BuilderBacking.Length > 0)
                    {
                        self.PushPendingCharactersToValue();
                    }

                    return(self.IsHeaderResult());
                }
                else
                {
                    self.AddToPushback(self.Buffer.Buffer.Span.Slice(0, available));
                }

                if (self.AdvanceWork(available))
                {
                    return(self.IsHeaderResult());
                }


                // go back into the loop
                while (true)
                {
                    available = await self.Buffer.ReadAsync(self.Inner, cancel);

                    if (available == 0)
                    {
                        if (self.BuilderBacking.Length > 0)
                        {
                            self.PushPendingCharactersToValue();
                        }
                        break;
                    }
                    else
                    {
                        self.AddToPushback(self.Buffer.Buffer.Span.Slice(0, available));
                    }

                    if (self.AdvanceWork(available))
                    {
                        break;
                    }
                }

                return(self.IsHeaderResult());
            }
Exemplo n.º 2
0
            // wait for read to complete, then continue async
            static async ValueTask <(HeaderEnumerator Headers, bool IsHeader, Memory <char> PushBack)> ReadAsync_ContinueAfterReadAsync(
                HeadersReader <T> self,
                ValueTask <int> waitFor,
                CancellationToken cancellationToken)
            {
                bool madeProgress;

                int available;

                {
                    available = await ConfigureCancellableAwait(self, waitFor, cancellationToken);
                }

                // handle the in flight task
                if (available == 0)
                {
                    if (self.BuilderBacking.Length > 0)
                    {
                        var inEscapedValue = ReaderStateMachine.IsInEscapedValue(self.StateMachine.CurrentState);
                        self.PushPendingCharactersToValue(inEscapedValue);
                    }

                    return(self.IsHeaderResult());
                }
                else
                {
                    self.AddToPushback(self.Buffer.Buffer.Span.Slice(0, available));
                }

                if (self.AdvanceWork(available, out madeProgress))
                {
                    return(self.IsHeaderResult());
                }

                // go back into the loop
                while (true)
                {
                    var readTask = self.Buffer.ReadAsync(self.InnerAsync.Value, madeProgress, cancellationToken);
                    {
                        available = await ConfigureCancellableAwait(self, readTask, cancellationToken);
                    }

                    if (available == 0)
                    {
                        if (self.BuilderBacking.Length > 0)
                        {
                            var inEscapedValue = ReaderStateMachine.IsInEscapedValue(self.StateMachine.CurrentState);
                            self.PushPendingCharactersToValue(inEscapedValue);
                        }
                        break;
                    }
                    else
                    {
                        self.AddToPushback(self.Buffer.Buffer.Span.Slice(0, available));
                    }

                    if (self.AdvanceWork(available, out madeProgress))
                    {
                        break;
                    }
                }

                return(self.IsHeaderResult());
            }