![]() |
O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
|
Read from buffered input streams. More...
#include "o2s/file_input_stream.h"
#include "o2s/log.h"
#include <errno.h>
#include <iso646.h>
#include <string.h>
#include <unistd.h>
#include <stdbool.h>
#include <threads.h>
Go to the source code of this file.
Functions | |
ssize_t | file_single_read (ifstream_t *file) |
Read as much as possible. | |
bool | file_accumulate_infinite (ifstream_t *file, size_t count) |
If possible, accumulate count bytes before returning. | |
bool | file_accumulate (ifstream_t *file, size_t count) |
If possible, accumulate count bytes before returning. | |
void | file_stop_reading (void) |
Prevent the accumulate function from calling read in this thread. | |
void | file_resume_reading (void) |
Resume calling read in this thread. | |
void | file_default_signal_handler (int, siginfo_t *, void *) |
Default signal handler. |
Read from buffered input streams.
Definition in file read.c.
bool file_accumulate | ( | ifstream_t * | file, |
size_t | count ) |
bool file_accumulate_infinite | ( | ifstream_t * | file, |
size_t | count ) |
If possible, accumulate count
bytes before returning.
This alternative keeps trying upon reaching the end of the file, waiting for new data to be written. It is suitable when reading pipes, serial ports and such infinite streams.
To set a timeout, create a timer that emits a signal with file_stop_reading as a signal handler, for the current read call to be interrupted and to break out of the loop.
ssize_t file_single_read | ( | ifstream_t * | file | ) |
void file_stop_reading | ( | void | ) |
Prevent the accumulate function from calling read in this thread.
This allows setting a thread specific timeout, that interrupts the current read, and exits the accumulating loop. The effect is thread_local, so multiple files can have their own timeouts in parallel.