Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::AsyncReadableStream Struct Reference

Async source abstraction emitting data events in caller provided byte buffers. More...

#include <AsyncStreams.h>

Inheritance diagram for SC::AsyncReadableStream:
SC::AsyncRequestReadableStream< AsyncRequestType >

Classes

struct  Request
 

Public Member Functions

Result init (AsyncBuffersPool &buffersPool, Span< Request > requests)
 Emitted when the underlying resource has been closed. More...
 
Result start ()
 Starts the readable stream, that will emit eventData. More...
 
void pause ()
 Pauses the readable stream (that can be later resumed) More...
 
void resume ()
 Resumes the readable stream paused by AsyncReadableStream::pause. More...
 
void destroy ()
 Forcefully destroys the readable stream before it's end event releasing all resources. More...
 
bool isEnded () const
 Returns true if the stream is ended (AsyncReadableStream::end has been called) More...
 
AsyncBuffersPoolgetBuffersPool ()
 Obtains the AsyncBuffersPool to request more buffers. More...
 
void push (AsyncBufferView::ID bufferID, size_t newSize)
 Use push from inside AsyncReadableStream::asyncRead function to queue received data. More...
 
void pushEnd ()
 Use pushEnd from inside AsyncReadableStream::asyncRead to signal production end. More...
 
void reactivate (bool doReactivate)
 Use reactivate(true) from inside AsyncReadableStream::asyncRead function to ask the state machine to invoke asyncRead again. More...
 
void emitError (Result error)
 Signals an async error received. More...
 
bool getBufferOrPause (size_t minumumSizeInBytes, AsyncBufferView::ID &bufferID, Span< char > &data)
 Returns an unused buffer from pool or pauses the stream if none is available. More...
 

Public Attributes

Function< Result()> asyncRead
 Function that every stream must define to implement its custom read operation. More...
 
Event< MaxListeners, ResulteventError
 
Event< MaxListeners, AsyncBufferView::IDeventData
 Emitted when an error occurs. More...
 
Event< MaxListeners > eventEnd
 Emitted when a new buffer has been read. More...
 
Event< MaxListeners > eventClose
 Emitted when there is no more data. More...
 

Static Public Attributes

static constexpr int MaxListeners = 8
 

Detailed Description

Async source abstraction emitting data events in caller provided byte buffers.

After AsyncReadableStream::start it will start emitting AsyncReadableStream::eventData with buffers. User must provide a custom async red implementation in AsyncReadableStream::asyncRead. The stream must be paused when the AsyncBuffersPool is full (use AsyncReadableStream::getBufferOrPause). Once the stream is ended, it will emit AsyncReadableStream::eventEnd and it cannot be used further. AsyncReadableStream::eventError will be emitted when an error occurs in any phase.

Member Function Documentation

◆ destroy()

void SC::AsyncReadableStream::destroy ( )

Forcefully destroys the readable stream before it's end event releasing all resources.

◆ emitError()

void SC::AsyncReadableStream::emitError ( Result  error)

Signals an async error received.

◆ getBufferOrPause()

bool SC::AsyncReadableStream::getBufferOrPause ( size_t  minumumSizeInBytes,
AsyncBufferView::ID bufferID,
Span< char > &  data 
)

Returns an unused buffer from pool or pauses the stream if none is available.

◆ getBuffersPool()

AsyncBuffersPool & SC::AsyncReadableStream::getBuffersPool ( )

Obtains the AsyncBuffersPool to request more buffers.

◆ init()

Result SC::AsyncReadableStream::init ( AsyncBuffersPool buffersPool,
Span< Request requests 
)

Emitted when the underlying resource has been closed.

Inits the readable stream with an AsyncBuffersPool instance that will provide memory for it

Parameters
buffersPoolAn instance of AsyncBuffersPool providing read buffers
requestsUser owned memory to hold a circular buffer for read requests

◆ isEnded()

bool SC::AsyncReadableStream::isEnded ( ) const
inline

Returns true if the stream is ended (AsyncReadableStream::end has been called)

◆ pause()

void SC::AsyncReadableStream::pause ( )

Pauses the readable stream (that can be later resumed)

◆ push()

void SC::AsyncReadableStream::push ( AsyncBufferView::ID  bufferID,
size_t  newSize 
)

Use push from inside AsyncReadableStream::asyncRead function to queue received data.

◆ pushEnd()

void SC::AsyncReadableStream::pushEnd ( )

Use pushEnd from inside AsyncReadableStream::asyncRead to signal production end.

◆ reactivate()

void SC::AsyncReadableStream::reactivate ( bool  doReactivate)

Use reactivate(true) from inside AsyncReadableStream::asyncRead function to ask the state machine to invoke asyncRead again.

◆ resume()

void SC::AsyncReadableStream::resume ( )

Resumes the readable stream paused by AsyncReadableStream::pause.

◆ start()

Result SC::AsyncReadableStream::start ( )

Starts the readable stream, that will emit eventData.

Member Data Documentation

◆ asyncRead

Function<Result()> SC::AsyncReadableStream::asyncRead

Function that every stream must define to implement its custom read operation.

◆ eventClose

Event<MaxListeners> SC::AsyncReadableStream::eventClose

Emitted when there is no more data.

◆ eventData

Event<MaxListeners, AsyncBufferView::ID> SC::AsyncReadableStream::eventData

Emitted when an error occurs.

◆ eventEnd

Event<MaxListeners> SC::AsyncReadableStream::eventEnd

Emitted when a new buffer has been read.


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