Skip to content

Commit 8f0e55d

Browse files
committed
Update ChunkedPipeWriter.cs
1 parent 0653c84 commit 8f0e55d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

frameworks/CSharp/aspnetcore/src/Platform/ChunkedPipeWriter.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal sealed class ChunkedPipeWriter : PipeWriter
2525
private Memory<byte> _currentFullChunk;
2626
private Memory<byte> _currentChunk;
2727
private int _buffered;
28+
private long _unflushedBytes;
2829
private bool _ended = false;
2930

3031
public Memory<byte> Memory => _currentChunk;
@@ -37,6 +38,7 @@ internal sealed class ChunkedPipeWriter : PipeWriter
3738
public void SetOutput(PipeWriter output, int chunkSizeHint = DefaultChunkSizeHint)
3839
{
3940
_buffered = 0;
41+
_unflushedBytes = 0;
4042
_chunkSizeHint = chunkSizeHint;
4143
_output = output;
4244

@@ -47,23 +49,25 @@ public void SetOutput(PipeWriter output, int chunkSizeHint = DefaultChunkSizeHin
4749
public void Reset()
4850
{
4951
_buffered = 0;
52+
_unflushedBytes = 0;
5053
_output = default;
5154
_ended = false;
5255
_hexFormat = DefaultHexFormat;
5356
_currentFullChunk = default;
5457
_currentChunk = default;
5558
}
5659

57-
public override bool CanGetUnflushedBytes => _output.CanGetUnflushedBytes;
60+
public override bool CanGetUnflushedBytes => true;
5861

59-
public override long UnflushedBytes => _output.UnflushedBytes;
62+
public override long UnflushedBytes => _unflushedBytes;
6063

6164
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6265
public override void Advance(int count)
6366
{
6467
ThrowIfEnded();
6568

6669
_buffered += count;
70+
_unflushedBytes += count;
6771
_currentChunk = _currentChunk[count..];
6872
}
6973

@@ -96,7 +100,13 @@ public override void Complete(Exception exception = null)
96100

97101
public override ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default)
98102
{
99-
return _output.FlushAsync(cancellationToken);
103+
CommitCurrentChunk(isFinal: false);
104+
105+
var flushTask = _output.FlushAsync(cancellationToken);
106+
107+
_unflushedBytes = 0;
108+
109+
return flushTask;
100110
}
101111

102112
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)