1 /* Copyright (C) 2007 Board of Trustees, Leland Stanford Jr. University.
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 /* Buffer for holding arbitrary data. A buffer is automatically reallocated as
28 * necessary if it grows too large for the available memory. */
30 void *base; /* First byte of area malloc()'d area. */
31 size_t allocated; /* Number of bytes allocated. */
33 void *data; /* First byte actually in use. */
34 size_t size; /* Number of bytes in use. */
36 void *l2; /* Link-level header. */
37 void *l3; /* Network-level header. */
38 void *l4; /* Transport-level header. */
40 struct buffer *next; /* Next in a list of buffers. */
43 void buffer_use(struct buffer *, void *, size_t);
45 void buffer_init(struct buffer *, size_t);
46 void buffer_uninit(struct buffer *);
47 void buffer_reinit(struct buffer *, size_t);
49 struct buffer *buffer_new(size_t);
50 struct buffer *buffer_clone(const struct buffer *);
51 void buffer_delete(struct buffer *);
53 void *buffer_at(const struct buffer *, size_t offset, size_t size);
54 void *buffer_at_assert(const struct buffer *, size_t offset, size_t size);
55 void *buffer_tail(const struct buffer *);
56 void *buffer_end(const struct buffer *);
58 void *buffer_put_uninit(struct buffer *, size_t);
59 void buffer_put(struct buffer *, const void *, size_t);
60 void *buffer_push_uninit(struct buffer *b, size_t);
62 size_t buffer_headroom(struct buffer *);
63 size_t buffer_tailroom(struct buffer *);
64 void buffer_reserve_tailroom(struct buffer *, size_t);
66 void buffer_clear(struct buffer *);
67 void buffer_pull(struct buffer *, size_t);