1 .\" $NetBSD: lwres_buffer.3,v 1.5 2014/12/10 04:38:02 christos Exp $
3 .\" Copyright (C) 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
4 .\" Copyright (C) 2000, 2001 Internet Software Consortium.
6 .\" Permission to use, copy, modify, and/or distribute this software for any
7 .\" purpose with or without fee is hereby granted, provided that the above
8 .\" copyright notice and this permission notice appear in all copies.
10 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 .\" PERFORMANCE OF THIS SOFTWARE.
22 .\" Title: lwres_buffer
24 .\" Generator: DocBook XSL Stylesheets v1.71.1 <http://docbook.sf.net/>
25 .\" Date: June 18, 2007
29 .TH "LWRES_BUFFER" "3" "June 18, 2007" "BIND9" "BIND9"
30 .\" disable hyphenation
32 .\" disable justification (adjust text to left margin only)
35 lwres_buffer_init, lwres_buffer_invalidate, lwres_buffer_add, lwres_buffer_subtract, lwres_buffer_clear, lwres_buffer_first, lwres_buffer_forward, lwres_buffer_back, lwres_buffer_getuint8, lwres_buffer_putuint8, lwres_buffer_getuint16, lwres_buffer_putuint16, lwres_buffer_getuint32, lwres_buffer_putuint32, lwres_buffer_putmem, lwres_buffer_getmem \- lightweight resolver buffer management
38 #include <lwres/lwbuffer.h>
41 .BI "void lwres_buffer_init(lwres_buffer_t\ *" "b" ", void\ *" "base" ", unsigned\ int\ " "length" ");"
43 .BI "void lwres_buffer_invalidate(lwres_buffer_t\ *" "b" ");"
45 .BI "void lwres_buffer_add(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
47 .BI "void lwres_buffer_subtract(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
49 .BI "void lwres_buffer_clear(lwres_buffer_t\ *" "b" ");"
51 .BI "void lwres_buffer_first(lwres_buffer_t\ *" "b" ");"
53 .BI "void lwres_buffer_forward(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
55 .BI "void lwres_buffer_back(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
57 .BI "lwres_uint8_t lwres_buffer_getuint8(lwres_buffer_t\ *" "b" ");"
59 .BI "void lwres_buffer_putuint8(lwres_buffer_t\ *" "b" ", lwres_uint8_t\ " "val" ");"
61 .BI "lwres_uint16_t lwres_buffer_getuint16(lwres_buffer_t\ *" "b" ");"
63 .BI "void lwres_buffer_putuint16(lwres_buffer_t\ *" "b" ", lwres_uint16_t\ " "val" ");"
65 .BI "lwres_uint32_t lwres_buffer_getuint32(lwres_buffer_t\ *" "b" ");"
67 .BI "void lwres_buffer_putuint32(lwres_buffer_t\ *" "b" ", lwres_uint32_t\ " "val" ");"
69 .BI "void lwres_buffer_putmem(lwres_buffer_t\ *" "b" ", const\ unsigned\ char\ *" "base" ", unsigned\ int\ " "length" ");"
71 .BI "void lwres_buffer_getmem(lwres_buffer_t\ *" "b" ", unsigned\ char\ *" "base" ", unsigned\ int\ " "length" ");"
74 These functions provide bounds checked access to a region of memory where data is being read or written. They are based on, and similar to, the
76 functions in the ISC library.
78 A buffer is a region of memory, together with a set of related subregions. The
82 region are disjoint, and their union is the buffer's region. The used region extends from the beginning of the buffer region to the last used byte. The available region extends from one byte greater than the last used byte to the end of the buffer's region. The size of the used region can be changed using various buffer commands. Initially, the used region is empty.
84 The used region is further subdivided into two disjoint regions: the
87 \fIremaining region\fR. The union of these two regions is the used region. The consumed region extends from the beginning of the used region to the byte before the
91 region the current pointer to the end of the used region. The size of the consumed region can be changed using various buffer commands. Initially, the consumed region is empty.
95 is an (optional) subregion of the remaining region. It extends from the current offset to an offset in the remaining region. Initially, the active region is empty. If the current offset advances beyond the chosen offset, the active region will also be empty.
99 /\-\-\-\-\-\-\-\-\-\-\-\-entire length\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\\\\
100 /\-\-\-\-\- used region \-\-\-\-\-\\\\/\-\- available \-\-\\\\
101 +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
102 | consumed | remaining | |
103 +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
112 b == current pointer. Can be anywhere between a and d.
113 c == active pointer. Meaningful between b and d.
115 e == length of buffer.
122 a\-e == entire length of buffer.
124 a\-b == consumed region.
125 b\-d == remaining region.
126 b\-c == optional active region.
131 \fBlwres_buffer_init()\fR
135 and assocates it with the memory region of size
137 bytes starting at location
140 \fBlwres_buffer_invalidate()\fR
143 as invalid. Invalidating a buffer after use is not required, but makes it possible to catch its possible accidental use.
146 \fBlwres_buffer_add()\fR
148 \fBlwres_buffer_subtract()\fR
149 respectively increase and decrease the used space in buffer
154 \fBlwres_buffer_add()\fR
155 checks for buffer overflow and
156 \fBlwres_buffer_subtract()\fR
157 checks for underflow. These functions do not allocate or deallocate memory. They just change the value of
160 A buffer is re\-initialised by
161 \fBlwres_buffer_clear()\fR. The function sets
168 \fBlwres_buffer_first\fR
169 makes the consumed region of buffer
173 to zero (the start of the buffer).
175 \fBlwres_buffer_forward()\fR
176 increases the consumed region of buffer
180 bytes, checking for overflow. Similarly,
181 \fBlwres_buffer_back()\fR
183 \fIb\fR's consumed region by
185 bytes and checks for underflow.
187 \fBlwres_buffer_getuint8()\fR
188 reads an unsigned 8\-bit integer from
191 \fBlwres_buffer_putuint8()\fR
192 writes the unsigned 8\-bit integer
197 \fBlwres_buffer_getuint16()\fR
199 \fBlwres_buffer_getuint32()\fR
201 \fBlwres_buffer_putuint8()\fR
202 except that they respectively read an unsigned 16\-bit or 32\-bit integer in network byte order from
204 \fBlwres_buffer_putuint16()\fR
206 \fBlwres_buffer_putuint32()\fR
207 writes the unsigned 16\-bit or 32\-bit integer
210 \fIb\fR, in network byte order.
212 Arbitrary amounts of data are read or written from a lightweight resolver buffer with
213 \fBlwres_buffer_getmem()\fR
215 \fBlwres_buffer_putmem()\fR
217 \fBlwres_buffer_putmem()\fR
224 \fBlwres_buffer_getmem()\fR
232 Copyright \(co 2004, 2005, 2007, 2014 Internet Systems Consortium, Inc. ("ISC")
234 Copyright \(co 2000, 2001 Internet Software Consortium.