CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Core Functions

Functions

StreamBuffer * sbufCreate (size_t targetsz)
 
void sbufRelease (StreamBuffer **sb)
 
void sbufError (StreamBuffer *sb)
 
bool sbufIsPull (StreamBuffer *sb)
 
bool sbufIsPush (StreamBuffer *sb)
 
bool sbufIsError (StreamBuffer *sb)
 
bool sbufIsPFinished (StreamBuffer *sb)
 
bool sbufIsCFinished (StreamBuffer *sb)
 

Detailed Description

Core stream buffer lifecycle and state management.

Operating Modes:

Push Mode: Producer repeatedly calls sbufPWrite(). Consumer is either notified that data is available via callback, or in direct mode, data is pushed immediately to the consumer's callback.

Pull Mode: Consumer repeatedly calls sbufCRead() or sbufCSend(). Producer's pull callback is invoked to fill the buffer as needed.

Function Documentation

◆ sbufCreate()

StreamBuffer * sbufCreate ( size_t  targetsz)

StreamBuffer *sbufCreate(size_t targetsz)

Creates a new stream buffer with the specified target size.

The buffer will automatically grow as needed but tries to stay near targetsz. Set targetsz to 0 only when using direct push mode (no buffering needed).

Parameters
targetszTarget buffer size in bytes (0 for direct mode)
Returns
New stream buffer (must be released with sbufRelease)

Example:

StreamBuffer *sb = sbufCreate(4096);
// ... register producer and consumer ...
StreamBuffer * sbufCreate(size_t targetsz)
void sbufRelease(StreamBuffer **sb)

◆ sbufError()

void sbufError ( StreamBuffer *  sb)

void sbufError(StreamBuffer *sb)

Puts the stream buffer into error state.

Processing will be aborted and both producer and consumer should call their respective Finish functions as soon as practical.

Parameters
sbThe stream buffer

◆ sbufIsCFinished()

bool sbufIsCFinished ( StreamBuffer *  sb)
inline

bool sbufIsCFinished(StreamBuffer *sb)

Checks if the consumer is finished.

Returns true if consumer has exited early (no longer needs data to be produced).

Parameters
sbThe stream buffer
Returns
true if consumer has finished or error occurred

Definition at line 234 of file streambuf.h.

References sbufIsError().

◆ sbufIsError()

bool sbufIsError ( StreamBuffer *  sb)
inline

bool sbufIsError(StreamBuffer *sb)

Checks if the stream buffer is in an error state.

Parameters
sbThe stream buffer
Returns
true if in error state

Definition at line 210 of file streambuf.h.

Referenced by sbufIsCFinished(), and sbufIsPFinished().

◆ sbufIsPFinished()

bool sbufIsPFinished ( StreamBuffer *  sb)
inline

bool sbufIsPFinished(StreamBuffer *sb)

Checks if the producer is finished (EOF).

Parameters
sbThe stream buffer
Returns
true if producer has finished or error occurred

Definition at line 221 of file streambuf.h.

References sbufIsError().

◆ sbufIsPull()

bool sbufIsPull ( StreamBuffer *  sb)
inline

bool sbufIsPull(StreamBuffer *sb)

Checks if the stream buffer is in pull mode.

Parameters
sbThe stream buffer
Returns
true if in pull mode

Definition at line 188 of file streambuf.h.

◆ sbufIsPush()

bool sbufIsPush ( StreamBuffer *  sb)
inline

bool sbufIsPush(StreamBuffer *sb)

Checks if the stream buffer is in push mode.

Parameters
sbThe stream buffer
Returns
true if in push mode

Definition at line 199 of file streambuf.h.

◆ sbufRelease()

void sbufRelease ( StreamBuffer **  sb)

void sbufRelease(StreamBuffer **sb)

Releases a reference to a stream buffer.

Decrements the reference count and destroys the buffer when it reaches zero. Sets the pointer to NULL after release.

Parameters
sbPointer to stream buffer pointer