CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Stream Buffers

Modules

 Core Functions
 
 Producer Functions
 
 Consumer Functions
 

Detailed Description

Stream buffers provide an efficient producer-consumer model for streaming data with automatic buffering and flow control. They support two primary modes:

Push Mode: Producer writes data via sbufPWrite(), consumer is notified or receives data directly via callbacks.

Pull Mode: Consumer reads data via sbufCRead(), producer's callback is invoked to fill the buffer as needed.

Basic Usage (Push Mode):

StreamBuffer *sb = sbufCreate(4096);
// Producer side
sbufPRegisterPush(sb, NULL, NULL);
sbufPWrite(sb, data, size);
// Consumer side (with notification callback)
sbufCRegisterPush(sb, myNotifyCallback, NULL, ctx);
// In callback: use sbufCRead() to retrieve data
bool sbufCRegisterPush(StreamBuffer *sb, sbufNotifyCB cnotify, sbufCleanupCB ccleanup, void *ctx)
StreamBuffer * sbufCreate(size_t targetsz)
void sbufPFinish(StreamBuffer *sb)
bool sbufPRegisterPush(StreamBuffer *sb, sbufCleanupCB pcleanup, void *ctx)
bool sbufPWrite(StreamBuffer *sb, const uint8 *buf, size_t sz)

Basic Usage (Pull Mode):

StreamBuffer *sb = sbufCreate(4096);
// Producer side (with pull callback)
sbufPRegisterPull(sb, myPullCallback, NULL, ctx);
// Consumer side
sbufCRegisterPull(sb, NULL, NULL);
size_t bytesread;
while (sbufCRead(sb, buffer, sizeof(buffer), &bytesread)) {
// process buffer
}
void sbufCFinish(StreamBuffer *sb)
bool sbufCRegisterPull(StreamBuffer *sb, sbufCleanupCB ccleanup, void *ctx)
bool sbufCRead(StreamBuffer *sb, uint8 *buf, size_t sz, size_t *bytesread)
bool sbufPRegisterPull(StreamBuffer *sb, sbufPullCB ppull, sbufCleanupCB pcleanup, void *ctx)