bio
 
Loading...
Searching...
No Matches
Buffering

Avoid making a lot of syscalls. More...

Data Structures

union  bio_io_buffer_ctx_t
 Context for a buffer function. More...
 
struct  bio_buffer_options_t
 Options for a buffer. More...
 
struct  bio_io_buffer_t
 Handle to a buffer. More...
 

Typedefs

typedef size_t(* bio_read_fn_t) (bio_io_buffer_ctx_t ctx, void *buf, size_t size, bio_error_t *error)
 Read callback.
 
typedef size_t(* bio_write_fn_t) (bio_io_buffer_ctx_t ctx, const void *buf, size_t size, bio_error_t *error)
 Write callback.
 
typedef bool(* bio_flush_fn_t) (bio_io_buffer_ctx_t ctx, bio_error_t *error)
 Flush callback.
 

Functions

bio_io_buffer_t bio_make_buffer (const bio_buffer_options_t *options)
 Create a new I/O buffer.
 
void bio_destroy_buffer (bio_io_buffer_t buffer)
 Destroy a buffer.
 
bio_io_buffer_t bio_make_file_read_buffer (bio_file_t file, size_t size)
 Create a read buffer for a file.
 
bio_io_buffer_t bio_make_file_write_buffer (bio_file_t file, size_t size, bool fflush)
 Create a write buffer for a file.
 
bio_io_buffer_t bio_make_socket_read_buffer (bio_socket_t socket, size_t size)
 Create a read buffer for a socket.
 
bio_io_buffer_t bio_make_socket_write_buffer (bio_socket_t socket, size_t size)
 Create a write buffer for a socket.
 
size_t bio_buffered_read (bio_io_buffer_t buffer, void *in, size_t size, bio_error_t *error)
 Read from a buffer.
 
size_t bio_buffered_write (bio_io_buffer_t buffer, const void *out, size_t size, bio_error_t *error)
 Write to a buffer.
 
bool bio_flush_buffer (bio_io_buffer_t buffer, bio_error_t *error)
 Flush all bufferred content.
 
static size_t bio_buffered_read_exactly (bio_io_buffer_t buffer, void *in, size_t size, bio_error_t *error)
 Helper to deal with short read.
 
static size_t bio_buffered_write_exactly (bio_io_buffer_t buffer, const void *out, size_t size, bio_error_t *error)
 Helper to deal with short write.
 

Detailed Description

Avoid making a lot of syscalls.

This is useful for delimitor-based protocols such as HTTP. Program code can just read character by character from the buffer until a delimitor is encountered. Data will get pulled as a block into the buffer as needed instead of single bytes.

Typedef Documentation

◆ bio_flush_fn_t

typedef bool(* bio_flush_fn_t) (bio_io_buffer_ctx_t ctx, bio_error_t *error)

Flush callback.

◆ bio_read_fn_t

typedef size_t(* bio_read_fn_t) (bio_io_buffer_ctx_t ctx, void *buf, size_t size, bio_error_t *error)

Read callback.

◆ bio_write_fn_t

typedef size_t(* bio_write_fn_t) (bio_io_buffer_ctx_t ctx, const void *buf, size_t size, bio_error_t *error)

Write callback.

Function Documentation

◆ bio_buffered_read()

size_t bio_buffered_read ( bio_io_buffer_t  buffer,
void *  in,
size_t  size,
bio_error_t error 
)

Read from a buffer.

◆ bio_buffered_read_exactly()

static size_t bio_buffered_read_exactly ( bio_io_buffer_t  buffer,
void *  in,
size_t  size,
bio_error_t error 
)
inlinestatic

Helper to deal with short read.

◆ bio_buffered_write()

size_t bio_buffered_write ( bio_io_buffer_t  buffer,
const void *  out,
size_t  size,
bio_error_t error 
)

Write to a buffer.

◆ bio_buffered_write_exactly()

static size_t bio_buffered_write_exactly ( bio_io_buffer_t  buffer,
const void *  out,
size_t  size,
bio_error_t error 
)
inlinestatic

Helper to deal with short write.

◆ bio_destroy_buffer()

void bio_destroy_buffer ( bio_io_buffer_t  buffer)

Destroy a buffer.

Existing data in a write buffer will be flushed.

◆ bio_flush_buffer()

bool bio_flush_buffer ( bio_io_buffer_t  buffer,
bio_error_t error 
)

Flush all bufferred content.

◆ bio_make_buffer()

bio_io_buffer_t bio_make_buffer ( const bio_buffer_options_t options)

Create a new I/O buffer.

Parameters
optionsOptions for this buffer
Returns
A new buffer
Remarks
A single buffer should only be used for either read or write, not both

◆ bio_make_file_read_buffer()

bio_io_buffer_t bio_make_file_read_buffer ( bio_file_t  file,
size_t  size 
)

Create a read buffer for a file.

◆ bio_make_file_write_buffer()

bio_io_buffer_t bio_make_file_write_buffer ( bio_file_t  file,
size_t  size,
bool  fflush 
)

Create a write buffer for a file.

Parameters
fileA file
sizeBuffer size
fflushWhether to call fflush on flush
Returns
A new io buffer

◆ bio_make_socket_read_buffer()

bio_io_buffer_t bio_make_socket_read_buffer ( bio_socket_t  socket,
size_t  size 
)

Create a read buffer for a socket.

◆ bio_make_socket_write_buffer()

bio_io_buffer_t bio_make_socket_write_buffer ( bio_socket_t  socket,
size_t  size 
)

Create a write buffer for a socket.