1 .\" Copyright (C) 2004 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.2 2004/03/15 04:45:00 marka Exp $
18 .TH "LWRES_BUFFER" "3" "Jun 30, 2000" "BIND9" ""
20 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
22 \fB#include <lwres/lwbuffer.h>
26 lwres_buffer_init(lwres_buffer_t *b, void *base, unsigned int length);
31 lwres_buffer_invalidate(lwres_buffer_t *b);
36 lwres_buffer_add(lwres_buffer_t *b, unsigned int n);
41 lwres_buffer_subtract(lwres_buffer_t *b, unsigned int n);
46 lwres_buffer_clear(lwres_buffer_t *b);
51 lwres_buffer_first(lwres_buffer_t *b);
56 lwres_buffer_forward(lwres_buffer_t *b, unsigned int n);
61 lwres_buffer_back(lwres_buffer_t *b, unsigned int n);
66 lwres_buffer_getuint8(lwres_buffer_t *b);
71 lwres_buffer_putuint8(lwres_buffer_t *b, lwres_uint8_t val);
76 lwres_buffer_getuint16(lwres_buffer_t *b);
81 lwres_buffer_putuint16(lwres_buffer_t *b, lwres_uint16_t val);
86 lwres_buffer_getuint32(lwres_buffer_t *b);
91 lwres_buffer_putuint32(lwres_buffer_t *b, lwres_uint32_t val);
96 lwres_buffer_putmem(lwres_buffer_t *b, const unsigned char *base, unsigned int length);
101 lwres_buffer_getmem(lwres_buffer_t *b, unsigned char *base, unsigned int length);
106 These functions provide bounds checked access to a region of memory
107 where data is being read or written.
108 They are based on, and similar to, the
110 functions in the ISC library.
112 A buffer is a region of memory, together with a set of related
114 The \fBused region\fR and the
115 \fBavailable\fR region are disjoint, and
116 their union is the buffer's region.
117 The used region extends from the beginning of the buffer region to the
119 The available region extends from one byte greater than the last used
120 byte to the end of the buffer's region.
121 The size of the used region can be changed using various
123 Initially, the used region is empty.
125 The used region is further subdivided into two disjoint regions: the
126 \fBconsumed region\fR and the \fBremaining region\fR.
127 The union of these two regions is the used region.
128 The consumed region extends from the beginning of the used region to
129 the byte before the \fBcurrent\fR offset (if any).
130 The \fBremaining\fR region the current pointer to the end of the used
132 The size of the consumed region can be changed using various
134 Initially, the consumed region is empty.
136 The \fBactive region\fR is an (optional) subregion of the remaining
138 It extends from the current offset to an offset in the
140 Initially, the active region is empty.
141 If the current offset advances beyond the chosen offset,
142 the active region will also be empty.
147 /------------entire length---------------\\\\
148 /----- used region -----\\\\/-- available --\\\\
149 +----------------------------------------+
150 | consumed | remaining | |
151 +----------------------------------------+
155 b == current pointer. Can be anywhere between a and d.
156 c == active pointer. Meaningful between b and d.
158 e == length of buffer.
160 a-e == entire length of buffer.
162 a-b == consumed region.
163 b-d == remaining region.
164 b-c == optional active region.
168 \fBlwres_buffer_init()\fR
172 and assocates it with the memory region of size
174 bytes starting at location
177 \fBlwres_buffer_invalidate()\fR
180 as invalid. Invalidating a buffer after use is not required,
181 but makes it possible to catch its possible accidental use.
184 \fBlwres_buffer_add()\fR
186 \fBlwres_buffer_subtract()\fR
187 respectively increase and decrease the used space in
193 \fBlwres_buffer_add()\fR
194 checks for buffer overflow and
195 \fBlwres_buffer_subtract()\fR
196 checks for underflow.
197 These functions do not allocate or deallocate memory.
198 They just change the value of
201 A buffer is re-initialised by
202 \fBlwres_buffer_clear()\fR.
210 \fBlwres_buffer_first\fR
211 makes the consumed region of buffer
215 to zero (the start of the buffer).
217 \fBlwres_buffer_forward()\fR
218 increases the consumed region of buffer
222 bytes, checking for overflow.
224 \fBlwres_buffer_back()\fR
229 bytes and checks for underflow.
231 \fBlwres_buffer_getuint8()\fR
232 reads an unsigned 8-bit integer from
235 \fBlwres_buffer_putuint8()\fR
236 writes the unsigned 8-bit integer
241 \fBlwres_buffer_getuint16()\fR
243 \fBlwres_buffer_getuint32()\fR
245 \fBlwres_buffer_putuint8()\fR
246 except that they respectively read an unsigned 16-bit or 32-bit integer
247 in network byte order from
250 \fBlwres_buffer_putuint16()\fR
252 \fBlwres_buffer_putuint32()\fR
253 writes the unsigned 16-bit or 32-bit integer
257 in network byte order.
259 Arbitrary amounts of data are read or written from a lightweight
261 \fBlwres_buffer_getmem()\fR
263 \fBlwres_buffer_putmem()\fR
265 \fBlwres_buffer_putmem()\fR
273 \fBlwres_buffer_getmem()\fR