lwres_buffer.docbook revision c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85
2433N/A<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2433N/A "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
2433N/A [<!ENTITY mdash "&#8212;">]>
2433N/A<!--
2433N/A - Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
2433N/A - Copyright (C) 2000, 2001 Internet Software Consortium.
2433N/A -
2433N/A - Permission to use, copy, modify, and distribute this software for any
2433N/A - purpose with or without fee is hereby granted, provided that the above
2433N/A - copyright notice and this permission notice appear in all copies.
2433N/A -
2433N/A - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
2433N/A - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2433N/A - AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
2433N/A - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2433N/A - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
2433N/A - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2433N/A - PERFORMANCE OF THIS SOFTWARE.
2433N/A-->
2433N/A
2433N/A<!-- $Id: lwres_buffer.docbook,v 1.9 2007/01/29 23:57:22 marka Exp $ -->
2433N/A<refentry>
2433N/A <refentryinfo>
2433N/A <date>Jun 30, 2000</date>
2433N/A </refentryinfo>
2433N/A
2433N/A <refmeta>
2433N/A <refentrytitle>lwres_buffer</refentrytitle>
2433N/A <manvolnum>3</manvolnum>
2433N/A <refmiscinfo>BIND9</refmiscinfo>
2433N/A </refmeta>
2433N/A
2433N/A <docinfo>
2488N/A <copyright>
2433N/A <year>2004</year>
2433N/A <year>2005</year>
2433N/A <year>2007</year>
2433N/A <holder>Internet Systems Consortium, Inc. ("ISC")</holder>
2433N/A </copyright>
2433N/A <copyright>
2433N/A <year>2000</year>
2433N/A <year>2001</year>
2433N/A <holder>Internet Software Consortium.</holder>
2433N/A </copyright>
2433N/A </docinfo>
2433N/A
2457N/A <refnamediv>
2457N/A <refname>lwres_buffer_init</refname>
2433N/A <refname>lwres_buffer_invalidate</refname>
2457N/A <refname>lwres_buffer_add</refname>
2457N/A <refname>lwres_buffer_subtract</refname>
2477N/A <refname>lwres_buffer_clear</refname>
2433N/A <refname>lwres_buffer_first</refname>
2433N/A <refname>lwres_buffer_forward</refname>
2433N/A <refname>lwres_buffer_back</refname>
2433N/A <refname>lwres_buffer_getuint8</refname>
2433N/A <refname>lwres_buffer_putuint8</refname>
2433N/A <refname>lwres_buffer_getuint16</refname>
2433N/A <refname>lwres_buffer_putuint16</refname>
2433N/A <refname>lwres_buffer_getuint32</refname>
2433N/A <refname>lwres_buffer_putuint32</refname>
2433N/A <refname>lwres_buffer_putmem</refname>
2433N/A <refname>lwres_buffer_getmem</refname>
2433N/A <refpurpose>lightweight resolver buffer management</refpurpose>
2433N/A </refnamediv>
2433N/A
2433N/A <refsynopsisdiv>
2433N/A
2433N/A <funcsynopsis>
2433N/A<funcsynopsisinfo>
2433N/A#include &lt;lwres/lwbuffer.h&gt;
2433N/A</funcsynopsisinfo>
2433N/A
2433N/A<funcprototype>
2433N/A
2433N/A <funcdef>
2433N/Avoid
2457N/A<function>lwres_buffer_init</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>void *<parameter>base</parameter></paramdef>
2457N/A <paramdef>unsigned int <parameter>length</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2433N/A<funcprototype>
2433N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_invalidate</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2433N/A </funcprototype>
2458N/A<funcprototype>
2458N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_add</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2433N/A <paramdef>unsigned int <parameter>n</parameter></paramdef>
2433N/A </funcprototype>
2433N/A
2433N/A<funcprototype>
2433N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_subtract</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2433N/A <paramdef>unsigned int <parameter>n</parameter></paramdef>
2433N/A </funcprototype>
2433N/A
2433N/A<funcprototype>
2433N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_clear</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2433N/A </funcprototype>
2433N/A
2433N/A<funcprototype>
2433N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_first</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2433N/A </funcprototype>
2433N/A
2433N/A<funcprototype>
2433N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_forward</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2433N/A <paramdef>unsigned int <parameter>n</parameter></paramdef>
2433N/A </funcprototype>
2433N/A<funcprototype>
2433N/A
2433N/A <funcdef>
2433N/Avoid
2433N/A<function>lwres_buffer_back</function></funcdef>
2433N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>unsigned int <parameter>n</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Alwres_uint8_t
2457N/A<function>lwres_buffer_getuint8</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Avoid
2457N/A<function>lwres_buffer_putuint8</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>lwres_uint8_t <parameter>val</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Alwres_uint16_t
2457N/A<function>lwres_buffer_getuint16</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Avoid
2457N/A<function>lwres_buffer_putuint16</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>lwres_uint16_t <parameter>val</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Alwres_uint32_t
2457N/A<function>lwres_buffer_getuint32</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Avoid
2457N/A<function>lwres_buffer_putuint32</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>lwres_uint32_t <parameter>val</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Avoid
2457N/A<function>lwres_buffer_putmem</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>const unsigned char *<parameter>base</parameter></paramdef>
2457N/A <paramdef>unsigned int <parameter>length</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A<funcprototype>
2457N/A <funcdef>
2457N/Avoid
2457N/A<function>lwres_buffer_getmem</function></funcdef>
2457N/A <paramdef>lwres_buffer_t *<parameter>b</parameter></paramdef>
2457N/A <paramdef>unsigned char *<parameter>base</parameter></paramdef>
2457N/A <paramdef>unsigned int <parameter>length</parameter></paramdef>
2457N/A </funcprototype>
2457N/A
2457N/A</funcsynopsis>
2457N/A </refsynopsisdiv>
2457N/A
2457N/A <refsect1>
2457N/A
2457N/A <title>DESCRIPTION</title>
2457N/A <para>
2457N/A These functions provide bounds checked access to a region of memory
2457N/A where data is being read or written.
2457N/A They are based on, and similar to, the
2457N/A <literal>isc_buffer_</literal>
2457N/A functions in the ISC library.
2457N/A </para>
2457N/A <para>
2457N/A A buffer is a region of memory, together with a set of related
2457N/A subregions.
2457N/A The <emphasis>used region</emphasis> and the
2457N/A <emphasis>available</emphasis> region are disjoint, and
2457N/A their union is the buffer's region.
2457N/A The used region extends from the beginning of the buffer region to the
2457N/A last used byte.
2457N/A The available region extends from one byte greater than the last used
2457N/A byte to the end of the buffer's region.
2457N/A The size of the used region can be changed using various
2457N/A buffer commands.
2457N/A Initially, the used region is empty.
2457N/A </para>
2457N/A <para>
2457N/A The used region is further subdivided into two disjoint regions: the
2457N/A <emphasis>consumed region</emphasis> and the <emphasis>remaining region</emphasis>.
2457N/A The union of these two regions is the used region.
2457N/A The consumed region extends from the beginning of the used region to
2457N/A the byte before the <emphasis>current</emphasis> offset (if any).
2433N/A The <emphasis>remaining</emphasis> region the current pointer to the end
2433N/A of the used
2433N/A region.
2433N/A The size of the consumed region can be changed using various
2433N/A buffer commands.
2433N/A Initially, the consumed region is empty.
2433N/A </para>
2433N/A <para>
2433N/A The <emphasis>active region</emphasis> is an (optional) subregion of the
2433N/A remaining
2433N/A region.
2433N/A It extends from the current offset to an offset in the
2433N/A remaining region.
2433N/A Initially, the active region is empty.
2433N/A If the current offset advances beyond the chosen offset,
2433N/A the active region will also be empty.
2433N/A </para>
2433N/A <para><programlisting>
2433N/A /------------entire length---------------\\
2433N/A /----- used region -----\\/-- available --\\
2433N/A +----------------------------------------+
2433N/A | consumed | remaining | |
2433N/A +----------------------------------------+
2433N/A a b c d e
2433N/A </programlisting>
2433N/A </para>
2433N/A <para><programlisting>
2433N/A a == base of buffer.
2433N/A b == current pointer. Can be anywhere between a and d.
2433N/A c == active pointer. Meaningful between b and d.
2433N/A d == used pointer.
2433N/A e == length of buffer.
2433N/A </programlisting>
2433N/A </para>
2433N/A <para><programlisting>
2433N/A a-e == entire length of buffer.
2433N/A a-d == used region.
2433N/A a-b == consumed region.
2433N/A b-d == remaining region.
2433N/A b-c == optional active region.
2433N/A</programlisting>
2433N/A </para>
2433N/A <para><function>lwres_buffer_init()</function>
2433N/A initializes the
2433N/A <type>lwres_buffer_t</type>
2433N/A <parameter>*b</parameter>
2433N/A and assocates it with the memory region of size
2433N/A <parameter>length</parameter>
2433N/A bytes starting at location
2433N/A <parameter>base.</parameter>
2433N/A </para>
2433N/A <para><function>lwres_buffer_invalidate()</function>
2433N/A marks the buffer <parameter>*b</parameter>
2433N/A as invalid. Invalidating a buffer after use is not required,
2433N/A but makes it possible to catch its possible accidental use.
2433N/A </para>
2433N/A <para>
2433N/A The functions
2433N/A <function>lwres_buffer_add()</function>
2433N/A and
2433N/A <function>lwres_buffer_subtract()</function>
2433N/A respectively increase and decrease the used space in
2433N/A buffer
2433N/A <parameter>*b</parameter>
2433N/A by
2433N/A <parameter>n</parameter>
2433N/A bytes.
2433N/A <function>lwres_buffer_add()</function>
2433N/A checks for buffer overflow and
2433N/A <function>lwres_buffer_subtract()</function>
2433N/A checks for underflow.
2433N/A These functions do not allocate or deallocate memory.
2433N/A They just change the value of
2433N/A <structfield>used</structfield>.
2433N/A </para>
2433N/A <para>
2433N/A A buffer is re-initialised by
2433N/A <function>lwres_buffer_clear()</function>.
2433N/A The function sets
2433N/A <structfield>used</structfield>,
2433N/A <structfield>current</structfield>
2433N/A and
2433N/A <structfield>active</structfield>
2433N/A to zero.
2433N/A </para>
2433N/A <para><function>lwres_buffer_first</function>
2433N/A makes the consumed region of buffer
2433N/A <parameter>*p</parameter>
2433N/A empty by setting
2433N/A <structfield>current</structfield>
2433N/A to zero (the start of the buffer).
2433N/A </para>
2433N/A <para><function>lwres_buffer_forward()</function>
2433N/A increases the consumed region of buffer
2433N/A <parameter>*b</parameter>
2433N/A by
2433N/A <parameter>n</parameter>
2433N/A bytes, checking for overflow.
2433N/A Similarly,
2433N/A <function>lwres_buffer_back()</function>
2433N/A decreases buffer
2433N/A <parameter>b</parameter>'s
2433N/A consumed region by
2433N/A <parameter>n</parameter>
2433N/A bytes and checks for underflow.
2433N/A </para>
2607N/A <para><function>lwres_buffer_getuint8()</function>
2607N/A reads an unsigned 8-bit integer from
2607N/A <parameter>*b</parameter>
2607N/A and returns it.
2607N/A <function>lwres_buffer_putuint8()</function>
2607N/A writes the unsigned 8-bit integer
2433N/A <parameter>val</parameter>
2433N/A to buffer
2433N/A <parameter>*b</parameter>.
2433N/A </para>
2433N/A <para><function>lwres_buffer_getuint16()</function>
2433N/A and
2433N/A <function>lwres_buffer_getuint32()</function>
2433N/A are identical to
2433N/A <function>lwres_buffer_putuint8()</function>
2433N/A except that they respectively read an unsigned 16-bit or 32-bit integer
2433N/A in network byte order from
2433N/A <parameter>b</parameter>.
2433N/A Similarly,
2433N/A <function>lwres_buffer_putuint16()</function>
2433N/A and
2433N/A <function>lwres_buffer_putuint32()</function>
2433N/A writes the unsigned 16-bit or 32-bit integer
2433N/A <parameter>val</parameter>
2433N/A to buffer
2433N/A <parameter>b</parameter>,
2433N/A in network byte order.
2433N/A </para>
2433N/A <para>
2433N/A Arbitrary amounts of data are read or written from a lightweight
2433N/A resolver buffer with
2433N/A <function>lwres_buffer_getmem()</function>
2433N/A and
2433N/A <function>lwres_buffer_putmem()</function>
2433N/A respectively.
2433N/A <function>lwres_buffer_putmem()</function>
2433N/A copies
2433N/A <parameter>length</parameter>
2433N/A bytes of memory at
2433N/A <parameter>base</parameter>
2433N/A to
2433N/A <parameter>b</parameter>.
2433N/A Conversely,
2433N/A <function>lwres_buffer_getmem()</function>
2433N/A copies
2433N/A <parameter>length</parameter>
2433N/A bytes of memory from
2433N/A <parameter>b</parameter>
2433N/A to
2433N/A <parameter>base</parameter>.
2433N/A </para>
2433N/A </refsect1>
2433N/A</refentry><!--
2433N/A - Local variables:
2433N/A - mode: sgml
2433N/A - End:
2458N/A-->
2433N/A