]>
Commit | Line | Data |
---|---|---|
00ecc5ce | 1 | /* Copyright (c) 2008, 2009, 2013 Nicira, Inc. |
064af421 | 2 | * |
a14bc59f BP |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at: | |
064af421 | 6 | * |
a14bc59f | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
064af421 | 8 | * |
a14bc59f BP |
9 | * Unless required by applicable law or agreed to in writing, software |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
064af421 BP |
14 | */ |
15 | ||
16 | #ifndef BYTEQ_H | |
17 | #define BYTEQ_H 1 | |
18 | ||
19 | #include <stdbool.h> | |
20 | #include <stddef.h> | |
21 | #include <stdint.h> | |
22 | ||
064af421 BP |
23 | /* General-purpose circular queue of bytes. */ |
24 | struct byteq { | |
00ecc5ce BP |
25 | uint8_t *buffer; /* Circular queue. */ |
26 | unsigned int size; /* Number of bytes allocated for 'buffer'. */ | |
064af421 BP |
27 | unsigned int head; /* Head of queue. */ |
28 | unsigned int tail; /* Chases the head. */ | |
29 | }; | |
30 | ||
00ecc5ce | 31 | void byteq_init(struct byteq *, uint8_t *buffer, size_t size); |
064af421 BP |
32 | int byteq_used(const struct byteq *); |
33 | int byteq_avail(const struct byteq *); | |
34 | bool byteq_is_empty(const struct byteq *); | |
35 | bool byteq_is_full(const struct byteq *); | |
36 | void byteq_put(struct byteq *, uint8_t c); | |
37 | void byteq_putn(struct byteq *, const void *, size_t n); | |
38 | void byteq_put_string(struct byteq *, const char *); | |
39 | uint8_t byteq_get(struct byteq *); | |
40 | int byteq_write(struct byteq *, int fd); | |
41 | int byteq_read(struct byteq *, int fd); | |
42 | ||
1c617a49 BP |
43 | uint8_t *byteq_head(struct byteq *); |
44 | int byteq_headroom(const struct byteq *); | |
45 | void byteq_advance_head(struct byteq *, unsigned int n); | |
46 | int byteq_tailroom(const struct byteq *); | |
47 | const uint8_t *byteq_tail(const struct byteq *); | |
48 | void byteq_advance_tail(struct byteq *, unsigned int n); | |
49 | ||
064af421 | 50 | #endif /* byteq.h */ |