Async source abstraction emitting data events in caller provided byte buffers. More...
#include <AsyncStreams.h>
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... | |
AsyncBuffersPool & | getBuffersPool () |
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, Result > | eventError |
Event< MaxListeners, AsyncBufferView::ID > | eventData |
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 |
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.
void SC::AsyncReadableStream::destroy | ( | ) |
Forcefully destroys the readable stream before it's end event releasing all resources.
void SC::AsyncReadableStream::emitError | ( | Result | error | ) |
Signals an async error received.
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.
AsyncBuffersPool & SC::AsyncReadableStream::getBuffersPool | ( | ) |
Obtains the AsyncBuffersPool to request more buffers.
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
buffersPool | An instance of AsyncBuffersPool providing read buffers |
requests | User owned memory to hold a circular buffer for read requests |
|
inline |
Returns true if the stream is ended (AsyncReadableStream::end has been called)
void SC::AsyncReadableStream::pause | ( | ) |
Pauses the readable stream (that can be later resumed)
void SC::AsyncReadableStream::push | ( | AsyncBufferView::ID | bufferID, |
size_t | newSize | ||
) |
Use push from inside AsyncReadableStream::asyncRead function to queue received data.
void SC::AsyncReadableStream::pushEnd | ( | ) |
Use pushEnd from inside AsyncReadableStream::asyncRead to signal production end.
void SC::AsyncReadableStream::reactivate | ( | bool | doReactivate | ) |
Use reactivate(true) from inside AsyncReadableStream::asyncRead function to ask the state machine to invoke asyncRead again.
void SC::AsyncReadableStream::resume | ( | ) |
Resumes the readable stream paused by AsyncReadableStream::pause.
Result SC::AsyncReadableStream::start | ( | ) |
Starts the readable stream, that will emit eventData.
Function that every stream must define to implement its custom read operation.
Event<MaxListeners> SC::AsyncReadableStream::eventClose |
Emitted when there is no more data.
Event<MaxListeners, AsyncBufferView::ID> SC::AsyncReadableStream::eventData |
Emitted when an error occurs.
Event<MaxListeners> SC::AsyncReadableStream::eventEnd |
Emitted when a new buffer has been read.