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

Functions

bool sbufPRegisterPull (StreamBuffer *sb, sbufPullCB ppull, sbufCleanupCB pcleanup, void *ctx)
 
bool sbufPRegisterPush (StreamBuffer *sb, sbufCleanupCB pcleanup, void *ctx)
 
size_t sbufPAvail (StreamBuffer *sb)
 
bool sbufPWrite (StreamBuffer *sb, const uint8 *buf, size_t sz)
 
bool sbufPWriteStr (StreamBuffer *sb, strref str)
 
bool sbufPWriteLine (StreamBuffer *sb, strref str)
 
bool sbufPWriteEOL (StreamBuffer *sb)
 
void sbufPFinish (StreamBuffer *sb)
 

Detailed Description

Functions for the producer side of stream buffer operations.

Function Documentation

◆ sbufPAvail()

size_t sbufPAvail ( StreamBuffer *  sb)

size_t sbufPAvail(StreamBuffer *sb)

Returns the available space for writing to the buffer.

Parameters
sbThe stream buffer
Returns
Number of bytes available for writing

◆ sbufPFinish()

void sbufPFinish ( StreamBuffer *  sb)

void sbufPFinish(StreamBuffer *sb)

Marks the producer as finished (EOF).

CRITICAL: The producer MUST NOT access the stream buffer after calling this function as it may be immediately deallocated.

Parameters
sbThe stream buffer (invalidated after call)

◆ sbufPRegisterPull()

bool sbufPRegisterPull ( StreamBuffer *  sb,
sbufPullCB  ppull,
sbufCleanupCB  pcleanup,
void *  ctx 
)

bool sbufPRegisterPull(StreamBuffer *sb, sbufPullCB ppull, sbufCleanupCB pcleanup, void *ctx)

Registers a producer with the stream buffer in pull mode.

In pull mode, the consumer pulls data by calling sbufCRead(), which triggers the producer's callback to fill the buffer.

Parameters
sbThe stream buffer
ppullPull callback to provide data
pcleanupOptional cleanup callback for ctx
ctxOptional user context passed to callbacks
Returns
true on success, false if already registered or invalid mode

◆ sbufPRegisterPush()

bool sbufPRegisterPush ( StreamBuffer *  sb,
sbufCleanupCB  pcleanup,
void *  ctx 
)

bool sbufPRegisterPush(StreamBuffer *sb, sbufCleanupCB pcleanup, void *ctx)

Registers a producer with the stream buffer in push mode.

In push mode, the producer pushes data by calling sbufPWrite(), which notifies or directly calls the consumer.

Parameters
sbThe stream buffer
pcleanupOptional cleanup callback for ctx
ctxOptional user context passed to cleanup
Returns
true on success, false if already registered or invalid mode

◆ sbufPWrite()

bool sbufPWrite ( StreamBuffer *  sb,
const uint8 *  buf,
size_t  sz 
)

bool sbufPWrite(StreamBuffer *sb, const uint8 *buf, size_t sz)

Writes data to the buffer.

This will always succeed unless the system is out of memory. An overflow buffer is used if written data exceeds current buffer size.

Parameters
sbThe stream buffer
bufData to write
szNumber of bytes to write
Returns
true on success, false if consumer finished or error

◆ sbufPWriteEOL()

bool sbufPWriteEOL ( StreamBuffer *  sb)

bool sbufPWriteEOL(StreamBuffer *sb)

Writes a system-dependent line ending to the buffer.

Uses \r\n on Windows, \n on Unix systems.

Parameters
sbThe stream buffer
Returns
true on success, false on error

◆ sbufPWriteLine()

bool sbufPWriteLine ( StreamBuffer *  sb,
strref  str 
)

bool sbufPWriteLine(StreamBuffer *sb, strref str)

Writes a string followed by a system-dependent line ending to the buffer.

Uses \r\n on Windows, \n on Unix systems.

Parameters
sbThe stream buffer
strString to write
Returns
true on success, false on error

◆ sbufPWriteStr()

bool sbufPWriteStr ( StreamBuffer *  sb,
strref  str 
)

bool sbufPWriteStr(StreamBuffer *sb, strref str)

Writes a string to the buffer.

Parameters
sbThe stream buffer
strString to write
Returns
true on success, false on error