1 /* Copyright (c) 2008, 2009, 2013 Nicira, 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 /* General-purpose circular queue of bytes. */
25 uint8_t *buffer; /* Circular queue. */
26 unsigned int size; /* Number of bytes allocated for 'buffer'. */
27 unsigned int head; /* Head of queue. */
28 unsigned int tail; /* Chases the head. */
31 void byteq_init(struct byteq *, uint8_t *buffer, size_t size);
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);
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);