1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 typedef struct Ring Ring;
28 uint8_t *buf; /* buffer or NULL */
29 size_t size; /* actual size of @buf */
30 size_t start; /* start position of ring */
31 size_t used; /* number of actually used bytes */
34 /* flush buffer so it is empty again */
35 void ring_flush(Ring *r);
37 /* flush buffer, free allocated data and reset to initial state */
38 void ring_clear(Ring *r);
40 /* get pointers to buffer data and their length */
41 size_t ring_peek(Ring *r, struct iovec *vec);
43 /* copy data into external linear buffer */
44 size_t ring_copy(Ring *r, void *buf, size_t size);
46 /* push data to the end of the buffer */
47 int ring_push(Ring *r, const void *u8, size_t size);
49 /* pull data from the front of the buffer */
50 void ring_pull(Ring *r, size_t size);
52 /* return size of occupied buffer in bytes */
53 static inline size_t ring_get_size(Ring *r)