Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ private void AdvanceReader(BufferSegment? consumedSegment, int consumedIndex, Bu
Debug.Assert(_unconsumedBytes >= 0, "Length has gone negative");

if (oldLength >= ResumeWriterThreshold &&
_unconsumedBytes < ResumeWriterThreshold)
(_unconsumedBytes < ResumeWriterThreshold ||
(_unconsumedBytes == 0 && ResumeWriterThreshold == 0)))
{
_writerAwaitable.Complete(out completionData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ public PipeOptions(
{
pauseWriterThreshold = DefaultPauseWriterThreshold;
}
else if (pauseWriterThreshold < 0)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.pauseWriterThreshold);
}

if (resumeWriterThreshold == -1)
{
resumeWriterThreshold = DefaultResumeWriterThreshold;
}

if (pauseWriterThreshold < 0)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.pauseWriterThreshold);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this block needs to move unless we're concerned about DefaultPauseWriterThreshold being less than 0. Where it was before would still throw an exception if pauseWriterThreshold was < -1 (due to the -1 check before it).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I think you want is the else if below these lines to just be if instead.

else if (resumeWriterThreshold < 0 || resumeWriterThreshold > pauseWriterThreshold)
{
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.resumeWriterThreshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Schedule(Action<object> action, object state)
public void CompletingReaderFromWriterCallbackWorks()
{
var callbackRan = false;
var pipe = new Pipe(new PipeOptions(_pool, pauseWriterThreshold: 5, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false));
var pipe = new Pipe(new PipeOptions(_pool, pauseWriterThreshold: 5, resumeWriterThreshold: 5, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false));

pipe.Writer.OnReaderCompleted((exception, state) => { pipe.Writer.Complete(); }, null);

Expand All @@ -61,7 +61,7 @@ public void CompletingReaderFromWriterCallbackWorks()
public void CompletingWriterFromReaderCallbackWorks()
{
var callbackRan = false;
var pipe = new Pipe(new PipeOptions(_pool, pauseWriterThreshold: 5, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false));
var pipe = new Pipe(new PipeOptions(_pool, pauseWriterThreshold: 5, resumeWriterThreshold: 5, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false));

pipe.Reader.OnWriterCompleted((exception, state) => { pipe.Reader.Complete(); }, null);

Expand Down Expand Up @@ -201,7 +201,7 @@ public void OnReaderCompletedRanBeforeFlushContinuation()
{
var callbackRan = false;
var continuationRan = false;
var pipe = new Pipe(new PipeOptions(_pool, pauseWriterThreshold: 5, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false));
var pipe = new Pipe(new PipeOptions(_pool, pauseWriterThreshold: 5, resumeWriterThreshold: 5, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false));

pipe.Writer.OnReaderCompleted(
(exception, state) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void InvalidArgs_Throws()
AssertExtensions.Throws<ArgumentOutOfRangeException>("pauseWriterThreshold", () => new PipeOptions(pauseWriterThreshold: -2));
AssertExtensions.Throws<ArgumentOutOfRangeException>("resumeWriterThreshold", () => new PipeOptions(resumeWriterThreshold: -2));
AssertExtensions.Throws<ArgumentOutOfRangeException>("resumeWriterThreshold", () => new PipeOptions(pauseWriterThreshold: 50, resumeWriterThreshold: 100));
AssertExtensions.Throws<ArgumentOutOfRangeException>("resumeWriterThreshold", () => new PipeOptions(pauseWriterThreshold: 1, resumeWriterThreshold: -1));
}

[Theory]
Expand Down