]>
Commit | Line | Data |
---|---|---|
e0edde6f | 1 | /* Copyright (c) 2008, 2009 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 | ||
23 | /* Maximum number of bytes in a byteq. */ | |
24 | #define BYTEQ_SIZE 512 | |
25 | ||
26 | /* General-purpose circular queue of bytes. */ | |
27 | struct byteq { | |
28 | uint8_t buffer[BYTEQ_SIZE]; /* Circular queue. */ | |
29 | unsigned int head; /* Head of queue. */ | |
30 | unsigned int tail; /* Chases the head. */ | |
31 | }; | |
32 | ||
33 | void byteq_init(struct byteq *); | |
34 | int byteq_used(const struct byteq *); | |
35 | int byteq_avail(const struct byteq *); | |
36 | bool byteq_is_empty(const struct byteq *); | |
37 | bool byteq_is_full(const struct byteq *); | |
38 | void byteq_put(struct byteq *, uint8_t c); | |
39 | void byteq_putn(struct byteq *, const void *, size_t n); | |
40 | void byteq_put_string(struct byteq *, const char *); | |
41 | uint8_t byteq_get(struct byteq *); | |
42 | int byteq_write(struct byteq *, int fd); | |
43 | int byteq_read(struct byteq *, int fd); | |
44 | ||
1c617a49 BP |
45 | uint8_t *byteq_head(struct byteq *); |
46 | int byteq_headroom(const struct byteq *); | |
47 | void byteq_advance_head(struct byteq *, unsigned int n); | |
48 | int byteq_tailroom(const struct byteq *); | |
49 | const uint8_t *byteq_tail(const struct byteq *); | |
50 | void byteq_advance_tail(struct byteq *, unsigned int n); | |
51 | ||
064af421 | 52 | #endif /* byteq.h */ |