4397f6aaaf23aec5a6423184b65f971b2254207f
[cascardo/ovs.git] / extras / ezio / byteq.h
1 /* Copyright (c) 2008, 2009 Nicira Networks, Inc.
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * In addition, as a special exception, Nicira Networks gives permission
17  * to link the code of its release of vswitchd with the OpenSSL project's
18  * "OpenSSL" library (or with modified versions of it that use the same
19  * license as the "OpenSSL" library), and distribute the linked
20  * executables.  You must obey the GNU General Public License in all
21  * respects for all of the code used other than "OpenSSL".  If you modify
22  * this file, you may extend this exception to your version of the file,
23  * but you are not obligated to do so.  If you do not wish to do so,
24  * delete this exception statement from your version.
25  *
26  */
27
28 #ifndef BYTEQ_H
29 #define BYTEQ_H 1
30
31 #include <stdbool.h>
32 #include <stddef.h>
33 #include <stdint.h>
34
35 /* Maximum number of bytes in a byteq. */
36 #define BYTEQ_SIZE 512
37
38 /* General-purpose circular queue of bytes. */
39 struct byteq {
40     uint8_t buffer[BYTEQ_SIZE]; /* Circular queue. */
41     unsigned int head;          /* Head of queue. */
42     unsigned int tail;          /* Chases the head. */
43 };
44
45 void byteq_init(struct byteq *);
46 int byteq_used(const struct byteq *);
47 int byteq_avail(const struct byteq *);
48 bool byteq_is_empty(const struct byteq *);
49 bool byteq_is_full(const struct byteq *);
50 void byteq_put(struct byteq *, uint8_t c);
51 void byteq_putn(struct byteq *, const void *, size_t n);
52 void byteq_put_string(struct byteq *, const char *);
53 uint8_t byteq_get(struct byteq *);
54 int byteq_write(struct byteq *, int fd);
55 int byteq_read(struct byteq *, int fd);
56
57 #endif /* byteq.h */