Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            InnerStream = readingStream ?? throw new ArgumentNullException(nameof(readingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options           = options;
            _bufferSegmentPool = new BufferSegmentStack(InitialSegmentPoolSize);
        }
Esempio n. 3
0
        public StreamPipeWriter(Stream writingStream, StreamPipeWriterOptions options)
        {
            InnerStream = writingStream ?? throw new ArgumentNullException(nameof(writingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _minimumBufferSize = options.MinimumBufferSize;
            _pool = options.Pool == MemoryPool <byte> .Shared ? null : options.Pool;
            _bufferSegmentPool = new BufferSegmentStack(InitialSegmentPoolSize);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            InnerStream = readingStream ?? throw new ArgumentNullException(nameof(readingStream));

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _bufferSegmentPool    = new BufferSegmentStack(InitialSegmentPoolSize);
            _minimumReadThreshold = Math.Min(options.MinimumReadSize, options.BufferSize);
            _pool       = options.Pool == MemoryPool <byte> .Shared ? null : options.Pool;
            _bufferSize = _pool == null ? options.BufferSize : Math.Min(options.BufferSize, _pool.MaxBufferSize);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a new StreamPipeReader.
        /// </summary>
        /// <param name="readingStream">The stream to read from.</param>
        /// <param name="options">The options to use.</param>
        public StreamPipeReader(Stream readingStream, StreamPipeReaderOptions options)
        {
            if (readingStream is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.readingStream);
            }
            if (options is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.options);
            }

            InnerStream        = readingStream;
            _options           = options;
            _bufferSegmentPool = new BufferSegmentStack(InitialSegmentPoolSize);
        }
Esempio n. 6
0
        public StreamPipeWriter(Stream writingStream, StreamPipeWriterOptions options)
        {
            if (writingStream is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.writingStream);
            }
            if (options is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.options);
            }

            InnerStream        = writingStream;
            _minimumBufferSize = options.MinimumBufferSize;
            _pool = options.Pool == MemoryPool <byte> .Shared ? null : options.Pool;
            _maxPooledBufferSize = _pool?.MaxBufferSize ?? -1;
            _bufferSegmentPool   = new BufferSegmentStack(InitialSegmentPoolSize);
            _leaveOpen           = options.LeaveOpen;
        }
Esempio n. 7
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);
        }