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.10 2006/06/29 13:02:31 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.70.1">
24 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
25 <a name="id2482688"></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>
61 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
63 <td><code class="funcdef">
65 <b class="fsfunc">lwres_buffer_invalidate</b>(</code></td>
77 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
79 <td><code class="funcdef">
81 <b class="fsfunc">lwres_buffer_add</b>(</code></td>
97 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
99 <td><code class="funcdef">
101 <b class="fsfunc">lwres_buffer_subtract</b>(</code></td>
117 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
119 <td><code class="funcdef">
121 <b class="fsfunc">lwres_buffer_clear</b>(</code></td>
133 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
135 <td><code class="funcdef">
137 <b class="fsfunc">lwres_buffer_first</b>(</code></td>
149 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
151 <td><code class="funcdef">
153 <b class="fsfunc">lwres_buffer_forward</b>(</code></td>
169 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
171 <td><code class="funcdef">
173 <b class="fsfunc">lwres_buffer_back</b>(</code></td>
189 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
191 <td><code class="funcdef">
193 <b class="fsfunc">lwres_buffer_getuint8</b>(</code></td>
205 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
207 <td><code class="funcdef">
209 <b class="fsfunc">lwres_buffer_putuint8</b>(</code></td>
225 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
227 <td><code class="funcdef">
229 <b class="fsfunc">lwres_buffer_getuint16</b>(</code></td>
241 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
243 <td><code class="funcdef">
245 <b class="fsfunc">lwres_buffer_putuint16</b>(</code></td>
261 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
263 <td><code class="funcdef">
265 <b class="fsfunc">lwres_buffer_getuint32</b>(</code></td>
277 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
279 <td><code class="funcdef">
281 <b class="fsfunc">lwres_buffer_putuint32</b>(</code></td>
297 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
299 <td><code class="funcdef">
301 <b class="fsfunc">lwres_buffer_putmem</b>(</code></td>
322 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
324 <td><code class="funcdef">
326 <b class="fsfunc">lwres_buffer_getmem</b>(</code></td>
349 <div class="refsect1" lang="en">
350 <a name="id2549674"></a><h2>DESCRIPTION</h2>
352 These functions provide bounds checked access to a region of memory
353 where data is being read or written.
354 They are based on, and similar to, the
355 <code class="literal">isc_buffer_</code>
356 functions in the ISC library.
359 A buffer is a region of memory, together with a set of related
361 The <span class="emphasis"><em>used region</em></span> and the
362 <span class="emphasis"><em>available</em></span> region are disjoint, and
363 their union is the buffer's region.
364 The used region extends from the beginning of the buffer region to the
366 The available region extends from one byte greater than the last used
367 byte to the end of the buffer's region.
368 The size of the used region can be changed using various
370 Initially, the used region is empty.
373 The used region is further subdivided into two disjoint regions: the
374 <span class="emphasis"><em>consumed region</em></span> and the <span class="emphasis"><em>remaining region</em></span>.
375 The union of these two regions is the used region.
376 The consumed region extends from the beginning of the used region to
377 the byte before the <span class="emphasis"><em>current</em></span> offset (if any).
378 The <span class="emphasis"><em>remaining</em></span> region the current pointer to the end of the used
380 The size of the consumed region can be changed using various
382 Initially, the consumed region is empty.
385 The <span class="emphasis"><em>active region</em></span> is an (optional) subregion of the remaining
387 It extends from the current offset to an offset in the
389 Initially, the active region is empty.
390 If the current offset advances beyond the chosen offset,
391 the active region will also be empty.
395 <pre class="programlisting">
397 /------------entire length---------------\\
398 /----- used region -----\\/-- available --\\
399 +----------------------------------------+
400 | consumed | remaining | |
401 +----------------------------------------+
405 b == current pointer. Can be anywhere between a and d.
406 c == active pointer. Meaningful between b and d.
408 e == length of buffer.
410 a-e == entire length of buffer.
412 a-b == consumed region.
413 b-d == remaining region.
414 b-c == optional active region.
419 <code class="function">lwres_buffer_init()</code>
421 <span class="type">lwres_buffer_t</span>
422 <em class="parameter"><code>*b</code></em>
423 and assocates it with the memory region of size
424 <em class="parameter"><code>length</code></em>
425 bytes starting at location
426 <em class="parameter"><code>base.</code></em>
429 <code class="function">lwres_buffer_invalidate()</code>
431 <em class="parameter"><code>*b</code></em>
432 as invalid. Invalidating a buffer after use is not required,
433 but makes it possible to catch its possible accidental use.
437 <code class="function">lwres_buffer_add()</code>
439 <code class="function">lwres_buffer_subtract()</code>
440 respectively increase and decrease the used space in
442 <em class="parameter"><code>*b</code></em>
444 <em class="parameter"><code>n</code></em>
446 <code class="function">lwres_buffer_add()</code>
447 checks for buffer overflow and
448 <code class="function">lwres_buffer_subtract()</code>
449 checks for underflow.
450 These functions do not allocate or deallocate memory.
451 They just change the value of
452 <em class="structfield"><code>used</code></em>.
455 A buffer is re-initialised by
456 <code class="function">lwres_buffer_clear()</code>.
458 <em class="structfield"><code>used</code></em> ,
459 <em class="structfield"><code>current</code></em>
461 <em class="structfield"><code>active</code></em>
465 <code class="function">lwres_buffer_first</code>
466 makes the consumed region of buffer
467 <em class="parameter"><code>*p</code></em>
469 <em class="structfield"><code>current</code></em>
470 to zero (the start of the buffer).
473 <code class="function">lwres_buffer_forward()</code>
474 increases the consumed region of buffer
475 <em class="parameter"><code>*b</code></em>
477 <em class="parameter"><code>n</code></em>
478 bytes, checking for overflow.
480 <code class="function">lwres_buffer_back()</code>
482 <em class="parameter"><code>b</code></em>'s
484 <em class="parameter"><code>n</code></em>
485 bytes and checks for underflow.
488 <code class="function">lwres_buffer_getuint8()</code>
489 reads an unsigned 8-bit integer from
490 <em class="parameter"><code>*b</code></em>
492 <code class="function">lwres_buffer_putuint8()</code>
493 writes the unsigned 8-bit integer
494 <em class="parameter"><code>val</code></em>
496 <em class="parameter"><code>*b</code></em>.
499 <code class="function">lwres_buffer_getuint16()</code>
501 <code class="function">lwres_buffer_getuint32()</code>
503 <code class="function">lwres_buffer_putuint8()</code>
504 except that they respectively read an unsigned 16-bit or 32-bit integer
505 in network byte order from
506 <em class="parameter"><code>b</code></em>.
508 <code class="function">lwres_buffer_putuint16()</code>
510 <code class="function">lwres_buffer_putuint32()</code>
511 writes the unsigned 16-bit or 32-bit integer
512 <em class="parameter"><code>val</code></em>
514 <em class="parameter"><code>b</code></em>,
515 in network byte order.
518 Arbitrary amounts of data are read or written from a lightweight
520 <code class="function">lwres_buffer_getmem()</code>
522 <code class="function">lwres_buffer_putmem()</code>
524 <code class="function">lwres_buffer_putmem()</code>
526 <em class="parameter"><code>length</code></em>
528 <em class="parameter"><code>base</code></em>
530 <em class="parameter"><code>b</code></em>.
532 <code class="function">lwres_buffer_getmem()</code>
534 <em class="parameter"><code>length</code></em>
536 <em class="parameter"><code>b</code></em>
538 <em class="parameter"><code>base</code></em>.