NanoByte.Common  2.9.0
NanoByte.Common.Streams.ProducerConsumerStream Class Reference

A stream that one producer can write to and one consumer can read from simultaneously. More...

Inheritance diagram for NanoByte.Common.Streams.ProducerConsumerStream:

Public Member Functions

 ProducerConsumerStream (int bufferSize=163840)
 Creates a new producer consumer stream. More...
 
override void SetLength (long value)
 Sets the estimated number of bytes that will run through this buffer in total. More...
 
override long Seek (long offset, SeekOrigin origin)
 
override void Flush ()
 
override int Read (byte[] buffer, int offset, int count)
 Reads data from the stream that was previously written. More...
 
override int Read (Span< byte > buffer)
 Reads data from the stream that was previously written. More...
 
override void CopyTo (Stream destination, int bufferSize)
 
override void Write (byte[] buffer, int offset, int count)
 Writes data to the stream to be later read. More...
 
override void Write (ReadOnlySpan< byte > buffer)
 Writes data to the stream to be later read. More...
 
void RelayErrorToReader (Exception exception)
 Throws an exception from within reader. More...
 
void DoneWriting ()
 Signals that no further write calls are intended and any blocked reader calls should return. More...
 

Protected Member Functions

override void Dispose (bool disposing)
 

Properties

override bool CanRead [get]
 
override bool CanWrite [get]
 
override bool CanSeek [get]
 
override long Position [get, set]
 Indicates how many bytes have been read from this buffer so far in total. More...
 
long PositionWrite [get]
 Indicates how many bytes have been written to this buffer so far in total. More...
 
override long Length [get]
 The estimated number of bytes that will run through this buffer in total; 0 for unknown. More...
 

Detailed Description

A stream that one producer can write to and one consumer can read from simultaneously.

Uses a circular buffer internally. Do not use more than one producer or consumer thread simultaneously!

Constructor & Destructor Documentation

◆ ProducerConsumerStream()

NanoByte.Common.Streams.ProducerConsumerStream.ProducerConsumerStream ( int  bufferSize = 163840)
inline

Creates a new producer consumer stream.

Parameters
bufferSizeThe maximum number of written but not read bytes the stream can buffer.

Member Function Documentation

◆ DoneWriting()

void NanoByte.Common.Streams.ProducerConsumerStream.DoneWriting ( )
inline

Signals that no further write calls are intended and any blocked reader calls should return.

◆ Read() [1/2]

override int NanoByte.Common.Streams.ProducerConsumerStream.Read ( byte[]  buffer,
int  offset,
int  count 
)

Reads data from the stream that was previously written.

◆ Read() [2/2]

override int NanoByte.Common.Streams.ProducerConsumerStream.Read ( Span< byte >  buffer)
inline

Reads data from the stream that was previously written.

◆ RelayErrorToReader()

void NanoByte.Common.Streams.ProducerConsumerStream.RelayErrorToReader ( Exception  exception)
inline

Throws an exception from within reader.

Parameters
exceptionThe exception to throw.

◆ SetLength()

override void NanoByte.Common.Streams.ProducerConsumerStream.SetLength ( long  value)

Sets the estimated number of bytes that will run through this buffer in total.

◆ Write() [1/2]

override void NanoByte.Common.Streams.ProducerConsumerStream.Write ( byte[]  buffer,
int  offset,
int  count 
)

Writes data to the stream to be later read.

◆ Write() [2/2]

override void NanoByte.Common.Streams.ProducerConsumerStream.Write ( ReadOnlySpan< byte >  buffer)
inline

Writes data to the stream to be later read.

Property Documentation

◆ Length

override long NanoByte.Common.Streams.ProducerConsumerStream.Length
get

The estimated number of bytes that will run through this buffer in total; 0 for unknown.

◆ Position

override long NanoByte.Common.Streams.ProducerConsumerStream.Position
getset

Indicates how many bytes have been read from this buffer so far in total.

◆ PositionWrite

long NanoByte.Common.Streams.ProducerConsumerStream.PositionWrite
get

Indicates how many bytes have been written to this buffer so far in total.


The documentation for this class was generated from the following file: