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):
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):
size_t bytesread;
while (
sbufCRead(sb, buffer,
sizeof(buffer), &bytesread)) {
}
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)