1 .\" Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
2 .\" Copyright (C) 2000, 2001 Internet Software Consortium.
4 .\" Permission to use, copy, modify, and distribute this software for any
5 .\" purpose with or without fee is hereby granted, provided that the above
6 .\" copyright notice and this permission notice appear in all copies.
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 .\" PERFORMANCE OF THIS SOFTWARE.
16 .\" $Id: lwres_buffer.3,v 1.12.2.1.8.6 2006/06/29 13:02:31 marka Exp $
20 .\" Title: lwres_buffer
22 .\" Generator: DocBook XSL Stylesheets v1.70.1 <http://docbook.sf.net/>
23 .\" Date: Jun 30, 2000
27 .TH "LWRES_BUFFER" "3" "Jun 30, 2000" "BIND9" "BIND9"
28 .\" disable hyphenation
30 .\" disable justification (adjust text to left margin only)
33 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
36 #include <lwres/lwbuffer.h>
39 .BI "void lwres_buffer_init(lwres_buffer_t\ *b, void\ *base, unsigned\ int\ length);"
41 .BI "void lwres_buffer_invalidate(lwres_buffer_t\ *b);"
43 .BI "void lwres_buffer_add(lwres_buffer_t\ *b, unsigned\ int\ n);"
45 .BI "void lwres_buffer_subtract(lwres_buffer_t\ *b, unsigned\ int\ n);"
47 .BI "void lwres_buffer_clear(lwres_buffer_t\ *b);"
49 .BI "void lwres_buffer_first(lwres_buffer_t\ *b);"
51 .BI "void lwres_buffer_forward(lwres_buffer_t\ *b, unsigned\ int\ n);"
53 .BI "void lwres_buffer_back(lwres_buffer_t\ *b, unsigned\ int\ n);"
55 .BI "lwres_uint8_t lwres_buffer_getuint8(lwres_buffer_t\ *b);"
57 .BI "void lwres_buffer_putuint8(lwres_buffer_t\ *b, lwres_uint8_t\ val);"
59 .BI "lwres_uint16_t lwres_buffer_getuint16(lwres_buffer_t\ *b);"
61 .BI "void lwres_buffer_putuint16(lwres_buffer_t\ *b, lwres_uint16_t\ val);"
63 .BI "lwres_uint32_t lwres_buffer_getuint32(lwres_buffer_t\ *b);"
65 .BI "void lwres_buffer_putuint32(lwres_buffer_t\ *b, lwres_uint32_t\ val);"
67 .BI "void lwres_buffer_putmem(lwres_buffer_t\ *b, const\ unsigned\ char\ *base, unsigned\ int\ length);"
69 .BI "void lwres_buffer_getmem(lwres_buffer_t\ *b, unsigned\ char\ *base, unsigned\ int\ length);"
72 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
74 functions in the ISC library.
76 A buffer is a region of memory, together with a set of related subregions. The
80 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.
82 The used region is further subdivided into two disjoint regions: the
85 \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
89 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.
93 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.
98 /\-\-\-\-\-\-\-\-\-\-\-\-entire length\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\\\\
99 /\-\-\-\-\- used region \-\-\-\-\-\\\\/\-\- available \-\-\\\\
100 +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
101 | consumed | remaining | |
102 +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
105 b == current pointer. Can be anywhere between a and d.
106 c == active pointer. Meaningful between b and d.
108 e == length of buffer.
109 a\-e == entire length of buffer.
111 a\-b == consumed region.
112 b\-d == remaining region.
113 b\-c == optional active region.
118 \fBlwres_buffer_init()\fR
122 and assocates it with the memory region of size
124 bytes starting at location
127 \fBlwres_buffer_invalidate()\fR
130 as invalid. Invalidating a buffer after use is not required, but makes it possible to catch its possible accidental use.
133 \fBlwres_buffer_add()\fR
135 \fBlwres_buffer_subtract()\fR
136 respectively increase and decrease the used space in buffer
141 \fBlwres_buffer_add()\fR
142 checks for buffer overflow and
143 \fBlwres_buffer_subtract()\fR
144 checks for underflow. These functions do not allocate or deallocate memory. They just change the value of
147 A buffer is re\-initialised by
148 \fBlwres_buffer_clear()\fR. The function sets
156 \fBlwres_buffer_first\fR
157 makes the consumed region of buffer
161 to zero (the start of the buffer).
163 \fBlwres_buffer_forward()\fR
164 increases the consumed region of buffer
168 bytes, checking for overflow. Similarly,
169 \fBlwres_buffer_back()\fR
171 \fIb\fR's consumed region by
173 bytes and checks for underflow.
175 \fBlwres_buffer_getuint8()\fR
176 reads an unsigned 8\-bit integer from
179 \fBlwres_buffer_putuint8()\fR
180 writes the unsigned 8\-bit integer
185 \fBlwres_buffer_getuint16()\fR
187 \fBlwres_buffer_getuint32()\fR
189 \fBlwres_buffer_putuint8()\fR
190 except that they respectively read an unsigned 16\-bit or 32\-bit integer in network byte order from
192 \fBlwres_buffer_putuint16()\fR
194 \fBlwres_buffer_putuint32()\fR
195 writes the unsigned 16\-bit or 32\-bit integer
198 \fIb\fR, in network byte order.
200 Arbitrary amounts of data are read or written from a lightweight resolver buffer with
201 \fBlwres_buffer_getmem()\fR
203 \fBlwres_buffer_putmem()\fR
205 \fBlwres_buffer_putmem()\fR
212 \fBlwres_buffer_getmem()\fR
220 Copyright \(co 2004, 2005 Internet Systems Consortium, Inc. ("ISC")