Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the <see cref="Pipe"/> with the specified <see cref="PipeOptions"/>.
        /// </summary>
        public Pipe(PipeOptions options)
        {
            if (options == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.options);
            }

            _bufferSegmentPool = new BufferSegmentStack(InitialSegmentPoolSize);

            _operationState   = default;
            _readerCompletion = default;
            _writerCompletion = default;

            // If we're using the default pool then mark it as null since we're just going to use the
            // array pool under the covers
            _pool = options.Pool == MemoryPool <byte> .Shared ? null : options.Pool;
            _maxPooledBufferSize       = _pool?.MaxBufferSize ?? 0;
            _minimumSegmentSize        = options.MinimumSegmentSize;
            _pauseWriterThreshold      = options.PauseWriterThreshold;
            _resumeWriterThreshold     = options.ResumeWriterThreshold;
            _readerScheduler           = options.ReaderScheduler;
            _writerScheduler           = options.WriterScheduler;
            _useSynchronizationContext = options.UseSynchronizationContext;
            _readerAwaitable           = new PipeAwaitable(completed: false, _useSynchronizationContext);
            _writerAwaitable           = new PipeAwaitable(completed: true, _useSynchronizationContext);
            _reader = new DefaultPipeReader(this);
            _writer = new DefaultPipeWriter(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the <see cref="Pipe"/> with the specified <see cref="PipeOptions"/>.
        /// </summary>
        public Pipe(PipeOptions options)
        {
            if (options == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.options);
            }

            _bufferSegmentPool = new BufferSegment[SegmentPoolSize];

            _operationState   = default;
            _readerCompletion = default;
            _writerCompletion = default;

            _pool = options.Pool;
            _minimumSegmentSize        = options.MinimumSegmentSize;
            _pauseWriterThreshold      = options.PauseWriterThreshold;
            _resumeWriterThreshold     = options.ResumeWriterThreshold;
            _readerScheduler           = options.ReaderScheduler;
            _writerScheduler           = options.WriterScheduler;
            _useSynchronizationContext = options.UseSynchronizationContext;
            _readerAwaitable           = new PipeAwaitable(completed: false, _useSynchronizationContext);
            _writerAwaitable           = new PipeAwaitable(completed: true, _useSynchronizationContext);
            _reader = new DefaultPipeReader(this);
            _writer = new DefaultPipeWriter(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the <see cref="Pipe"/> with the specified <see cref="PipeOptions"/>.
        /// </summary>
        public Pipe(PipeOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.ResumeWriterThreshold < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options.ResumeWriterThreshold));
            }

            if (options.PauseWriterThreshold < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options.PauseWriterThreshold));
            }

            if (options.ResumeWriterThreshold > options.PauseWriterThreshold)
            {
                throw new ArgumentException(nameof(options.PauseWriterThreshold) + " should be greater or equal to " + nameof(options.ResumeWriterThreshold), nameof(options.PauseWriterThreshold));
            }

            _bufferSegmentPool = new BufferSegment[SegmentPoolSize];

            _pool = options.Pool;
            _minimumSegmentSize = options.MinimumSegmentSize;
            _maximumSizeHigh    = options.PauseWriterThreshold;
            _maximumSizeLow     = options.ResumeWriterThreshold;
            _readerScheduler    = options.ReaderScheduler ?? PipeScheduler.Inline;
            _writerScheduler    = options.WriterScheduler ?? PipeScheduler.Inline;
            _readerAwaitable    = new PipeAwaitable(completed: false);
            _writerAwaitable    = new PipeAwaitable(completed: true);
            Reader = new DefaultPipeReader(this);
            Writer = new DefaultPipeWriter(this);
        }
Ejemplo n.º 4
0
        /// <summary>Initializes a new instance of the <see cref="System.IO.Pipelines.Pipe" /> class with the specified options.</summary>
        /// <param name="options">The set of options for this pipe.</param>
        public Pipe(PipeOptions options)
        {
            if (options == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.options);
            }

            _bufferSegmentPool = new BufferSegmentStack(options.InitialSegmentPoolSize);

            _operationState   = default;
            _readerCompletion = default;
            _writerCompletion = default;

            _options         = options;
            _readerAwaitable = new PipeAwaitable(completed: false, UseSynchronizationContext);
            _writerAwaitable = new PipeAwaitable(completed: true, UseSynchronizationContext);
            _reader          = new DefaultPipeReader(this);
            _writer          = new DefaultPipeWriter(this);
        }