]> git.proxmox.com Git - systemd.git/blame - src/basic/ring.h
Imported Upstream version 226
[systemd.git] / src / basic / ring.h
CommitLineData
60f067b4
JS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
9
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.
14
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.
19
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/>.
22***/
23
60f067b4 24
5eef597e
MP
25typedef struct Ring Ring;
26
27struct Ring {
60f067b4
JS
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 */
32};
33
34/* flush buffer so it is empty again */
5eef597e 35void ring_flush(Ring *r);
60f067b4
JS
36
37/* flush buffer, free allocated data and reset to initial state */
5eef597e 38void ring_clear(Ring *r);
60f067b4
JS
39
40/* get pointers to buffer data and their length */
5eef597e 41size_t ring_peek(Ring *r, struct iovec *vec);
60f067b4
JS
42
43/* copy data into external linear buffer */
5eef597e 44size_t ring_copy(Ring *r, void *buf, size_t size);
60f067b4
JS
45
46/* push data to the end of the buffer */
5eef597e 47int ring_push(Ring *r, const void *u8, size_t size);
60f067b4
JS
48
49/* pull data from the front of the buffer */
5eef597e 50void ring_pull(Ring *r, size_t size);
60f067b4
JS
51
52/* return size of occupied buffer in bytes */
d9dfd233 53static inline size_t ring_get_size(Ring *r) {
60f067b4
JS
54 return r->used;
55}