2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
33 * This is a general purpose FIFO buffer library. You may append data
34 * at the end, while another instance reads data from the beginning.
35 * It is optimized for zero-copy usage: you get pointers to the real
36 * buffer, where you may operate on.
38 * This library is not thread safe.
41 #ifndef MPD_FIFO_BUFFER_H
42 #define MPD_FIFO_BUFFER_H
50 * Creates a new #fifo_buffer object. Free this object with
53 * @param size the size of the buffer in bytes
54 * @return the new #fifo_buffer object
57 fifo_buffer_new(size_t size
);
60 * Frees the resources consumed by this #fifo_buffer object.
63 fifo_buffer_free(struct fifo_buffer
*buffer
);
66 * Clears all data currently in this #fifo_buffer object. This does
67 * not overwrite the actuall buffer; it just resets the internal
71 fifo_buffer_clear(struct fifo_buffer
*buffer
);
74 * Reads from the beginning of the buffer. To remove consumed data
75 * from the buffer, call fifo_buffer_consume().
77 * @param buffer the #fifo_buffer object
78 * @param length_r the maximum amount to read is returned here
79 * @return a pointer to the beginning of the buffer, or NULL if the
83 fifo_buffer_read(const struct fifo_buffer
*buffer
, size_t *length_r
);
86 * Marks data at the beginning of the buffer as "consumed".
88 * @param buffer the #fifo_buffer object
89 * @param length the number of bytes which were consumed
92 fifo_buffer_consume(struct fifo_buffer
*buffer
, size_t length
);
95 * Prepares writing to the buffer. This returns a buffer which you
96 * can write to. To commit the write operation, call
97 * fifo_buffer_append().
99 * @param buffer the #fifo_buffer object
100 * @param max_length_r the maximum amount to write is returned here
101 * @return a pointer to the end of the buffer, or NULL if the buffer
105 fifo_buffer_write(struct fifo_buffer
*buffer
, size_t *max_length_r
);
108 * Commits the write operation initiated by fifo_buffer_write().
110 * @param buffer the #fifo_buffer object
111 * @param length the number of bytes which were written
114 fifo_buffer_append(struct fifo_buffer
*buffer
, size_t length
);
117 * Checks if the buffer is empty.
120 fifo_buffer_is_empty(struct fifo_buffer
*buffer
);
123 * Checks if the buffer is full.
126 fifo_buffer_is_full(struct fifo_buffer
*buffer
);