|
CX Framework
Cross-platform C utility framework
|
Functions | |
| bool | _sbufFileIn (StreamBuffer *sb, File *file, bool close) |
| bool | _sbufFilePRegisterPull (StreamBuffer *sb, File *file, bool close) |
Functions for using files as stream buffer data sources.
| bool _sbufFileIn | ( | StreamBuffer * | sb, |
| File * | file, | ||
| bool | close | ||
| ) |
bool sbufFileIn(StreamBuffer *sb, File *file, bool close)
Reads a file and pushes its entire contents into a stream buffer.
Automatically chunks the data based on the stream buffer's target size for efficient operation. The stream buffer is automatically finished after all data is read.
If flow control is active (see sbufSetWatermark()), this waits for the consumer to make room rather than dropping data, so the consumer has to be draining the buffer from another thread.
| sb | The stream buffer |
| file | File to read from (optionally closed based on close parameter) |
| close | If true, the file is closed after reading |
Example:
| bool _sbufFilePRegisterPull | ( | StreamBuffer * | sb, |
| File * | file, | ||
| bool | close | ||
| ) |
bool sbufFilePRegisterPull(StreamBuffer *sb, File *file, bool close)
Registers a file as a producer with the stream buffer in pull mode.
In pull mode, the consumer pulls data as needed, and the file is read in chunks on demand. Use this instead of sbufFileIn() when you need finer control over when data is read.
The registration holds its own reference to the file until the producer slot is handed back, so the caller may release its own at any time after this returns.
| sb | The stream buffer |
| file | File to read from. With close set, the caller's reference is handed over with it and the handle must not be used again |
| close | If true, the file is closed when the producer finishes |