O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
read.c File Reference

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.

Detailed Description

Read from buffered input streams.

Author
Antoine GAGNIERE

Definition in file read.c.

Function Documentation

◆ file_accumulate()

bool file_accumulate ( ifstream_t * file,
size_t count )

If possible, accumulate count bytes before returning.

This alternative exits upon reaching the end of the file. It is suitable when reading regular files

Returns
a boolean
  • true if n bytes were successfully accumulated
  • false otherwise

Definition at line 87 of file read.c.

◆ file_accumulate_infinite()

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.

Returns
a boolean
  • true if n bytes were successfully accumulated
  • false otherwise

Definition at line 69 of file read.c.

◆ file_single_read()

ssize_t file_single_read ( ifstream_t * file)

Read as much as possible.

Attempt to fill the buffer

Definition at line 38 of file read.c.

◆ file_stop_reading()

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.

Definition at line 100 of file read.c.