PipeOptions
Represents a set of Pipe options.
using System.Buffers;
using System.Runtime.CompilerServices;
namespace System.IO.Pipelines
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class PipeOptions
{
private const int DefaultMinimumSegmentSize = 4096;
public static PipeOptions Default { get; } = new PipeOptions(null, null, null, -1, -1, -1, true);
public bool UseSynchronizationContext { get; }
public long PauseWriterThreshold { get; }
public long ResumeWriterThreshold { get; }
public int MinimumSegmentSize { get; }
public PipeScheduler WriterScheduler { get; }
public PipeScheduler ReaderScheduler { get; }
public MemoryPool<byte> Pool { get; }
internal bool { get; }
internal int InitialSegmentPoolSize { get; }
internal int MaxSegmentPoolSize { get; }
[System.Runtime.CompilerServices.NullableContext(2)]
public PipeOptions(MemoryPool<byte> pool = null, PipeScheduler readerScheduler = null, PipeScheduler writerScheduler = null, long pauseWriterThreshold = -1, long resumeWriterThreshold = -1, int minimumSegmentSize = -1, bool useSynchronizationContext = true)
{
MinimumSegmentSize = ((minimumSegmentSize == -1) ? 4096 : minimumSegmentSize);
InitialSegmentPoolSize = 4;
MaxSegmentPoolSize = 256;
if (pauseWriterThreshold == -1)
pauseWriterThreshold = 65536;
else if (pauseWriterThreshold < 0) {
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.pauseWriterThreshold);
}
switch (resumeWriterThreshold) {
case -1:
resumeWriterThreshold = 32768;
break;
case 0:
resumeWriterThreshold = 1;
break;
}
if (resumeWriterThreshold < 0 || (pauseWriterThreshold > 0 && resumeWriterThreshold > pauseWriterThreshold))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.resumeWriterThreshold);
Pool = (pool ?? MemoryPool<byte>.Shared);
IsDefaultSharedMemoryPool = (Pool == MemoryPool<byte>.Shared);
ReaderScheduler = (readerScheduler ?? PipeScheduler.ThreadPool);
WriterScheduler = (writerScheduler ?? PipeScheduler.ThreadPool);
PauseWriterThreshold = pauseWriterThreshold;
ResumeWriterThreshold = resumeWriterThreshold;
UseSynchronizationContext = useSynchronizationContext;
}
}
}