示例#1
0
        private async Task ProcessDataWrites()
        {
            try
            {
                ReadResult readResult;

                do
                {
                    readResult = await _dataPipe.Reader.ReadAsync();

                    await _frameWriter.WriteDataAsync(_streamId, _flowControl, readResult.Buffer, endStream : readResult.IsCompleted);

                    _dataPipe.Reader.AdvanceTo(readResult.Buffer.End);
                } while (!readResult.IsCompleted);
            }
            catch (ConnectionAbortedException)
            {
                // Writes should not throw for aborted connections.
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.ToString());
            }

            _dataPipe.Reader.Complete();
        }
        private async Task ProcessDataWrites()
        {
            try
            {
                ReadResult readResult;

                do
                {
                    readResult = await _dataPipe.Reader.ReadAsync();

                    if (readResult.IsCompleted && _stream.Trailers?.Count > 0)
                    {
                        if (readResult.Buffer.Length > 0)
                        {
                            await _frameWriter.WriteDataAsync(_streamId, _flowControl, readResult.Buffer, endStream : false);
                        }

                        await _frameWriter.WriteResponseTrailers(_streamId, _stream.Trailers);
                    }
                    else
                    {
                        await _frameWriter.WriteDataAsync(_streamId, _flowControl, readResult.Buffer, endStream : readResult.IsCompleted);
                    }

                    _dataPipe.Reader.AdvanceTo(readResult.Buffer.End);
                } while (!readResult.IsCompleted);
            }
            catch (OperationCanceledException)
            {
                // Writes should not throw for aborted streams/connections.
            }
            catch (Exception ex)
            {
                Debug.Assert(false, ex.ToString());
            }

            _dataPipe.Reader.Complete();
        }