2 - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001 Internet Software Consortium.
5 - Permission to use, copy, modify, and distribute this software for any
6 - purpose with or without fee is hereby granted, provided that the above
7 - copyright notice and this permission notice appear in all copies.
9 - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 - PERFORMANCE OF THIS SOFTWARE.
17 <!-- $Id: lwres_buffer.html,v 1.4.2.1.4.8 2005/10/13 02:33:55 marka Exp $ -->
20 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
21 <title>lwres_buffer</title>
22 <meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2463721"></a><div class="titlepage"></div>
26 <div class="refnamediv">
28 <p>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</p>
30 <div class="refsynopsisdiv">
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">
34 #include <lwres/lwbuffer.h>
36 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
38 <td><code class="funcdef">
40 <b class="fsfunc">lwres_buffer_init</b>(</code></td>
56 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
57 <td><code class="funcdef">
59 <b class="fsfunc">lwres_buffer_invalidate</b>(</code></td>
64 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
66 <td><code class="funcdef">
68 <b class="fsfunc">lwres_buffer_add</b>(</code></td>
79 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
81 <td><code class="funcdef">
83 <b class="fsfunc">lwres_buffer_subtract</b>(</code></td>
94 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
95 <td><code class="funcdef">
97 <b class="fsfunc">lwres_buffer_clear</b>(</code></td>
102 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
103 <td><code class="funcdef">
105 <b class="fsfunc">lwres_buffer_first</b>(</code></td>
110 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
112 <td><code class="funcdef">
114 <b class="fsfunc">lwres_buffer_forward</b>(</code></td>
125 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
127 <td><code class="funcdef">
129 <b class="fsfunc">lwres_buffer_back</b>(</code></td>
140 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
141 <td><code class="funcdef">
143 <b class="fsfunc">lwres_buffer_getuint8</b>(</code></td>
148 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
150 <td><code class="funcdef">
152 <b class="fsfunc">lwres_buffer_putuint8</b>(</code></td>
163 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
164 <td><code class="funcdef">
166 <b class="fsfunc">lwres_buffer_getuint16</b>(</code></td>
171 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
173 <td><code class="funcdef">
175 <b class="fsfunc">lwres_buffer_putuint16</b>(</code></td>
186 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
187 <td><code class="funcdef">
189 <b class="fsfunc">lwres_buffer_getuint32</b>(</code></td>
194 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
196 <td><code class="funcdef">
198 <b class="fsfunc">lwres_buffer_putuint32</b>(</code></td>
209 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
211 <td><code class="funcdef">
213 <b class="fsfunc">lwres_buffer_putmem</b>(</code></td>
229 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
231 <td><code class="funcdef">
233 <b class="fsfunc">lwres_buffer_getmem</b>(</code></td>
251 <div class="refsect1" lang="en">
252 <a name="id2526109"></a><h2>DESCRIPTION</h2>
254 These functions provide bounds checked access to a region of memory
255 where data is being read or written.
256 They are based on, and similar to, the
257 <code class="literal">isc_buffer_</code>
258 functions in the ISC library.
261 A buffer is a region of memory, together with a set of related
263 The <span class="emphasis"><em>used region</em></span> and the
264 <span class="emphasis"><em>available</em></span> region are disjoint, and
265 their union is the buffer's region.
266 The used region extends from the beginning of the buffer region to the
268 The available region extends from one byte greater than the last used
269 byte to the end of the buffer's region.
270 The size of the used region can be changed using various
272 Initially, the used region is empty.
275 The used region is further subdivided into two disjoint regions: the
276 <span class="emphasis"><em>consumed region</em></span> and the <span class="emphasis"><em>remaining region</em></span>.
277 The union of these two regions is the used region.
278 The consumed region extends from the beginning of the used region to
279 the byte before the <span class="emphasis"><em>current</em></span> offset (if any).
280 The <span class="emphasis"><em>remaining</em></span> region the current pointer to the end of the used
282 The size of the consumed region can be changed using various
284 Initially, the consumed region is empty.
287 The <span class="emphasis"><em>active region</em></span> is an (optional) subregion of the remaining
289 It extends from the current offset to an offset in the
291 Initially, the active region is empty.
292 If the current offset advances beyond the chosen offset,
293 the active region will also be empty.
297 <pre class="programlisting">
299 /------------entire length---------------\\
300 /----- used region -----\\/-- available --\\
301 +----------------------------------------+
302 | consumed | remaining | |
303 +----------------------------------------+
307 b == current pointer. Can be anywhere between a and d.
308 c == active pointer. Meaningful between b and d.
310 e == length of buffer.
312 a-e == entire length of buffer.
314 a-b == consumed region.
315 b-d == remaining region.
316 b-c == optional active region.
321 <code class="function">lwres_buffer_init()</code>
323 <span class="type">lwres_buffer_t</span>
324 <em class="parameter"><code>*b</code></em>
325 and assocates it with the memory region of size
326 <em class="parameter"><code>length</code></em>
327 bytes starting at location
328 <em class="parameter"><code>base.</code></em>
331 <code class="function">lwres_buffer_invalidate()</code>
333 <em class="parameter"><code>*b</code></em>
334 as invalid. Invalidating a buffer after use is not required,
335 but makes it possible to catch its possible accidental use.
339 <code class="function">lwres_buffer_add()</code>
341 <code class="function">lwres_buffer_subtract()</code>
342 respectively increase and decrease the used space in
344 <em class="parameter"><code>*b</code></em>
346 <em class="parameter"><code>n</code></em>
348 <code class="function">lwres_buffer_add()</code>
349 checks for buffer overflow and
350 <code class="function">lwres_buffer_subtract()</code>
351 checks for underflow.
352 These functions do not allocate or deallocate memory.
353 They just change the value of
354 <em class="structfield"><code>used</code></em>.
357 A buffer is re-initialised by
358 <code class="function">lwres_buffer_clear()</code>.
360 <em class="structfield"><code>used</code></em> ,
361 <em class="structfield"><code>current</code></em>
363 <em class="structfield"><code>active</code></em>
367 <code class="function">lwres_buffer_first</code>
368 makes the consumed region of buffer
369 <em class="parameter"><code>*p</code></em>
371 <em class="structfield"><code>current</code></em>
372 to zero (the start of the buffer).
375 <code class="function">lwres_buffer_forward()</code>
376 increases the consumed region of buffer
377 <em class="parameter"><code>*b</code></em>
379 <em class="parameter"><code>n</code></em>
380 bytes, checking for overflow.
382 <code class="function">lwres_buffer_back()</code>
384 <em class="parameter"><code>b</code></em>'s
386 <em class="parameter"><code>n</code></em>
387 bytes and checks for underflow.
390 <code class="function">lwres_buffer_getuint8()</code>
391 reads an unsigned 8-bit integer from
392 <em class="parameter"><code>*b</code></em>
394 <code class="function">lwres_buffer_putuint8()</code>
395 writes the unsigned 8-bit integer
396 <em class="parameter"><code>val</code></em>
398 <em class="parameter"><code>*b</code></em>.
401 <code class="function">lwres_buffer_getuint16()</code>
403 <code class="function">lwres_buffer_getuint32()</code>
405 <code class="function">lwres_buffer_putuint8()</code>
406 except that they respectively read an unsigned 16-bit or 32-bit integer
407 in network byte order from
408 <em class="parameter"><code>b</code></em>.
410 <code class="function">lwres_buffer_putuint16()</code>
412 <code class="function">lwres_buffer_putuint32()</code>
413 writes the unsigned 16-bit or 32-bit integer
414 <em class="parameter"><code>val</code></em>
416 <em class="parameter"><code>b</code></em>,
417 in network byte order.
420 Arbitrary amounts of data are read or written from a lightweight
422 <code class="function">lwres_buffer_getmem()</code>
424 <code class="function">lwres_buffer_putmem()</code>
426 <code class="function">lwres_buffer_putmem()</code>
428 <em class="parameter"><code>length</code></em>
430 <em class="parameter"><code>base</code></em>
432 <em class="parameter"><code>b</code></em>.
434 <code class="function">lwres_buffer_getmem()</code>
436 <em class="parameter"><code>length</code></em>
438 <em class="parameter"><code>b</code></em>
440 <em class="parameter"><code>base</code></em>.