1 /* Copyright (c) 2008, 2009 Nicira Networks, Inc.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 /* Maximum number of bytes in a byteq. */
24 #define BYTEQ_SIZE 512
26 /* General-purpose circular queue of bytes. */
28 uint8_t buffer[BYTEQ_SIZE]; /* Circular queue. */
29 unsigned int head; /* Head of queue. */
30 unsigned int tail; /* Chases the head. */
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);
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);