src/fifo_buffer.h File Reference

This is a general purpose FIFO buffer library. More...

#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Functions

struct fifo_buffer * fifo_buffer_new (size_t size)
 Creates a new fifo_buffer object.
void fifo_buffer_free (struct fifo_buffer *buffer)
 Frees the resources consumed by this fifo_buffer object.
void fifo_buffer_clear (struct fifo_buffer *buffer)
 Clears all data currently in this fifo_buffer object.
const void * fifo_buffer_read (const struct fifo_buffer *buffer, size_t *length_r)
 Reads from the beginning of the buffer.
void fifo_buffer_consume (struct fifo_buffer *buffer, size_t length)
 Marks data at the beginning of the buffer as "consumed".
void * fifo_buffer_write (struct fifo_buffer *buffer, size_t *max_length_r)
 Prepares writing to the buffer.
void fifo_buffer_append (struct fifo_buffer *buffer, size_t length)
 Commits the write operation initiated by fifo_buffer_write().
bool fifo_buffer_is_empty (struct fifo_buffer *buffer)
 Checks if the buffer is empty.
bool fifo_buffer_is_full (struct fifo_buffer *buffer)
 Checks if the buffer is full.


Detailed Description

This is a general purpose FIFO buffer library.

You may append data at the end, while another instance reads data from the beginning. It is optimized for zero-copy usage: you get pointers to the real buffer, where you may operate on.

This library is not thread safe.

Definition in file fifo_buffer.h.


Function Documentation

void fifo_buffer_append ( struct fifo_buffer *  buffer,
size_t  length 
)

Commits the write operation initiated by fifo_buffer_write().

Parameters:
buffer the fifo_buffer object
length the number of bytes which were written

void fifo_buffer_clear ( struct fifo_buffer *  buffer  ) 

Clears all data currently in this fifo_buffer object.

This does not overwrite the actuall buffer; it just resets the internal pointers.

void fifo_buffer_consume ( struct fifo_buffer *  buffer,
size_t  length 
)

Marks data at the beginning of the buffer as "consumed".

Parameters:
buffer the fifo_buffer object
length the number of bytes which were consumed

void fifo_buffer_free ( struct fifo_buffer *  buffer  ) 

Frees the resources consumed by this fifo_buffer object.

bool fifo_buffer_is_empty ( struct fifo_buffer *  buffer  ) 

Checks if the buffer is empty.

bool fifo_buffer_is_full ( struct fifo_buffer *  buffer  ) 

Checks if the buffer is full.

struct fifo_buffer* fifo_buffer_new ( size_t  size  )  [read]

Creates a new fifo_buffer object.

Free this object with fifo_buffer_free().

Parameters:
size the size of the buffer in bytes
Returns:
the new fifo_buffer object

const void* fifo_buffer_read ( const struct fifo_buffer *  buffer,
size_t *  length_r 
)

Reads from the beginning of the buffer.

To remove consumed data from the buffer, call fifo_buffer_consume().

Parameters:
buffer the fifo_buffer object
length_r the maximum amount to read is returned here
Returns:
a pointer to the beginning of the buffer, or NULL if the buffer is empty

void* fifo_buffer_write ( struct fifo_buffer *  buffer,
size_t *  max_length_r 
)

Prepares writing to the buffer.

This returns a buffer which you can write to. To commit the write operation, call fifo_buffer_append().

Parameters:
buffer the fifo_buffer object
max_length_r the maximum amount to write is returned here
Returns:
a pointer to the end of the buffer, or NULL if the buffer is already full


Generated on Wed Aug 25 00:21:21 2010 for MPD by  doxygen 1.5.7.1