|
MPD
0.17~git
|
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. | |
| struct fifo_buffer * | fifo_buffer_realloc (struct fifo_buffer *buffer, size_t new_size) |
| Change the capacity of the #fifo_buffer, while preserving existing data. | |
| void | fifo_buffer_free (struct fifo_buffer *buffer) |
| Frees the resources consumed by this #fifo_buffer object. | |
| size_t | fifo_buffer_capacity (const struct fifo_buffer *buffer) |
| Return the capacity of the buffer, i.e. | |
| size_t | fifo_buffer_available (const struct fifo_buffer *buffer) |
| Return the number of bytes currently stored in the buffer. | |
| 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. | |
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.
| void fifo_buffer_append | ( | struct fifo_buffer * | buffer, |
| size_t | length | ||
| ) |
Commits the write operation initiated by fifo_buffer_write().
| buffer | the #fifo_buffer object |
| length | the number of bytes which were written |
| size_t fifo_buffer_available | ( | const struct fifo_buffer * | buffer | ) |
Return the number of bytes currently stored in the buffer.
| size_t fifo_buffer_capacity | ( | const struct fifo_buffer * | buffer | ) |
Return the capacity of the buffer, i.e.
the size that was passed to fifo_buffer_new().
| 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".
| 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().
| size | the size of the buffer in bytes |
| 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().
| buffer | the #fifo_buffer object |
| length_r | the maximum amount to read is returned here |
| struct fifo_buffer* fifo_buffer_realloc | ( | struct fifo_buffer * | buffer, |
| size_t | new_size | ||
| ) | [read] |
Change the capacity of the #fifo_buffer, while preserving existing data.
| buffer | the old buffer, may be NULL |
| new_size | the requested new size of the #fifo_buffer; must not be smaller than the data which is stored in the old buffer |
| 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().
| buffer | the #fifo_buffer object |
| max_length_r | the maximum amount to write is returned here |
1.7.5.1