1 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.0//EN"
2 "http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd"
3 [<!ENTITY mdash "—">]>
5 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
6 - Copyright (C) 2000, 2001 Internet Software Consortium.
8 - Permission to use, copy, modify, and distribute this software for any
9 - purpose with or without fee is hereby granted, provided that the above
10 - copyright notice and this permission notice appear in all copies.
12 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
13 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18 - PERFORMANCE OF THIS SOFTWARE.
21 <!-- $Id: lwres_buffer.docbook,v 1.3.206.3 2005/05/12 21:36:11 sra Exp $ -->
25 <date>Jun 30, 2000</date>
29 <refentrytitle>lwres_buffer</refentrytitle>
30 <manvolnum>3</manvolnum>
31 <refmiscinfo>BIND9</refmiscinfo>
38 <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
43 <holder>Internet Software Consortium.</holder>
48 <refname>lwres_buffer_init</refname>
49 <refname>lwres_buffer_invalidate</refname>
50 <refname>lwres_buffer_add</refname>
51 <refname>lwres_buffer_subtract</refname>
52 <refname>lwres_buffer_clear</refname>
53 <refname>lwres_buffer_first</refname>
54 <refname>lwres_buffer_forward</refname>
55 <refname>lwres_buffer_back</refname>
56 <refname>lwres_buffer_getuint8</refname>
57 <refname>lwres_buffer_putuint8</refname>
58 <refname>lwres_buffer_getuint16</refname>
59 <refname>lwres_buffer_putuint16</refname>
60 <refname>lwres_buffer_getuint32</refname>
61 <refname>lwres_buffer_putuint32</refname>
62 <refname>lwres_buffer_putmem</refname>
63 <refname>lwres_buffer_getmem</refname>
64 <refpurpose>lightweight resolver buffer management</refpurpose>
71 #include <lwres/lwbuffer.h>
78 <function>lwres_buffer_init</function></funcdef>
79 <paramdef>lwres_buffer_t *b</paramdef>
80 <paramdef>void *base</paramdef>
81 <paramdef>unsigned int length</paramdef>
87 <function>lwres_buffer_invalidate</function></funcdef>
88 <paramdef>lwres_buffer_t *b</paramdef>
93 <function>lwres_buffer_add</function></funcdef>
94 <paramdef>lwres_buffer_t *b</paramdef>
95 <paramdef>unsigned int n</paramdef>
101 <function>lwres_buffer_subtract</function></funcdef>
102 <paramdef>lwres_buffer_t *b</paramdef>
103 <paramdef>unsigned int n</paramdef>
109 <function>lwres_buffer_clear</function></funcdef>
110 <paramdef>lwres_buffer_t *b</paramdef>
116 <function>lwres_buffer_first</function></funcdef>
117 <paramdef>lwres_buffer_t *b</paramdef>
123 <function>lwres_buffer_forward</function></funcdef>
124 <paramdef>lwres_buffer_t *b</paramdef>
125 <paramdef>unsigned int n</paramdef>
131 <function>lwres_buffer_back</function></funcdef>
132 <paramdef>lwres_buffer_t *b</paramdef>
133 <paramdef>unsigned int n</paramdef>
139 <function>lwres_buffer_getuint8</function></funcdef>
140 <paramdef>lwres_buffer_t *b</paramdef>
146 <function>lwres_buffer_putuint8</function></funcdef>
147 <paramdef>lwres_buffer_t *b</paramdef>
148 <paramdef>lwres_uint8_t val</paramdef>
154 <function>lwres_buffer_getuint16</function></funcdef>
155 <paramdef>lwres_buffer_t *b</paramdef>
161 <function>lwres_buffer_putuint16</function></funcdef>
162 <paramdef>lwres_buffer_t *b</paramdef>
163 <paramdef>lwres_uint16_t val</paramdef>
169 <function>lwres_buffer_getuint32</function></funcdef>
170 <paramdef>lwres_buffer_t *b</paramdef>
176 <function>lwres_buffer_putuint32</function></funcdef>
177 <paramdef>lwres_buffer_t *b</paramdef>
178 <paramdef>lwres_uint32_t val</paramdef>
184 <function>lwres_buffer_putmem</function></funcdef>
185 <paramdef>lwres_buffer_t *b</paramdef>
186 <paramdef>const unsigned char *base</paramdef>
187 <paramdef>unsigned int length</paramdef>
193 <function>lwres_buffer_getmem</function></funcdef>
194 <paramdef>lwres_buffer_t *b</paramdef>
195 <paramdef>unsigned char *base</paramdef>
196 <paramdef>unsigned int length</paramdef>
204 <title>DESCRIPTION</title>
206 These functions provide bounds checked access to a region of memory
207 where data is being read or written.
208 They are based on, and similar to, the
209 <literal>isc_buffer_</literal>
210 functions in the ISC library.
213 A buffer is a region of memory, together with a set of related
215 The <emphasis>used region</emphasis> and the
216 <emphasis>available</emphasis> region are disjoint, and
217 their union is the buffer's region.
218 The used region extends from the beginning of the buffer region to the
220 The available region extends from one byte greater than the last used
221 byte to the end of the buffer's region.
222 The size of the used region can be changed using various
224 Initially, the used region is empty.
227 The used region is further subdivided into two disjoint regions: the
228 <emphasis>consumed region</emphasis> and the <emphasis>remaining region</emphasis>.
229 The union of these two regions is the used region.
230 The consumed region extends from the beginning of the used region to
231 the byte before the <emphasis>current</emphasis> offset (if any).
232 The <emphasis>remaining</emphasis> region the current pointer to the end of the used
234 The size of the consumed region can be changed using various
236 Initially, the consumed region is empty.
239 The <emphasis>active region</emphasis> is an (optional) subregion of the remaining
241 It extends from the current offset to an offset in the
243 Initially, the active region is empty.
244 If the current offset advances beyond the chosen offset,
245 the active region will also be empty.
250 /------------entire length---------------\\
251 /----- used region -----\\/-- available --\\
252 +----------------------------------------+
253 | consumed | remaining | |
254 +----------------------------------------+
258 b == current pointer. Can be anywhere between a and d.
259 c == active pointer. Meaningful between b and d.
261 e == length of buffer.
263 a-e == entire length of buffer.
265 a-b == consumed region.
266 b-d == remaining region.
267 b-c == optional active region.
271 <function>lwres_buffer_init()</function>
273 <type>lwres_buffer_t</type>
274 <parameter>*b</parameter>
275 and assocates it with the memory region of size
276 <parameter>length</parameter>
277 bytes starting at location
278 <parameter>base.</parameter>
281 <function>lwres_buffer_invalidate()</function>
283 <parameter>*b</parameter>
284 as invalid. Invalidating a buffer after use is not required,
285 but makes it possible to catch its possible accidental use.
289 <function>lwres_buffer_add()</function>
291 <function>lwres_buffer_subtract()</function>
292 respectively increase and decrease the used space in
294 <parameter>*b</parameter>
296 <parameter>n</parameter>
298 <function>lwres_buffer_add()</function>
299 checks for buffer overflow and
300 <function>lwres_buffer_subtract()</function>
301 checks for underflow.
302 These functions do not allocate or deallocate memory.
303 They just change the value of
304 <structfield>used</structfield>.
307 A buffer is re-initialised by
308 <function>lwres_buffer_clear()</function>.
310 <structfield>used</structfield> ,
311 <structfield>current</structfield>
313 <structfield>active</structfield>
317 <function>lwres_buffer_first</function>
318 makes the consumed region of buffer
319 <parameter>*p</parameter>
321 <structfield>current</structfield>
322 to zero (the start of the buffer).
325 <function>lwres_buffer_forward()</function>
326 increases the consumed region of buffer
327 <parameter>*b</parameter>
329 <parameter>n</parameter>
330 bytes, checking for overflow.
332 <function>lwres_buffer_back()</function>
334 <parameter>b</parameter>'s
336 <parameter>n</parameter>
337 bytes and checks for underflow.
340 <function>lwres_buffer_getuint8()</function>
341 reads an unsigned 8-bit integer from
342 <parameter>*b</parameter>
344 <function>lwres_buffer_putuint8()</function>
345 writes the unsigned 8-bit integer
346 <parameter>val</parameter>
348 <parameter>*b</parameter>.
351 <function>lwres_buffer_getuint16()</function>
353 <function>lwres_buffer_getuint32()</function>
355 <function>lwres_buffer_putuint8()</function>
356 except that they respectively read an unsigned 16-bit or 32-bit integer
357 in network byte order from
358 <parameter>b</parameter>.
360 <function>lwres_buffer_putuint16()</function>
362 <function>lwres_buffer_putuint32()</function>
363 writes the unsigned 16-bit or 32-bit integer
364 <parameter>val</parameter>
366 <parameter>b</parameter>,
367 in network byte order.
370 Arbitrary amounts of data are read or written from a lightweight
372 <function>lwres_buffer_getmem()</function>
374 <function>lwres_buffer_putmem()</function>
376 <function>lwres_buffer_putmem()</function>
378 <parameter>length</parameter>
380 <parameter>base</parameter>
382 <parameter>b</parameter>.
384 <function>lwres_buffer_getmem()</function>
386 <parameter>length</parameter>
388 <parameter>b</parameter>
390 <parameter>base</parameter>.