2 - Copyright (C) 2004, 2005, 2007, 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
3 - Copyright (C) 2000, 2001 Internet Software Consortium.
5 - Permission to use, copy, modify, and/or 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.
19 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
20 <title>lwres_buffer</title>
21 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
23 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry">
24 <a name="id-1"></a><div class="titlepage"></div>
25 <div class="refnamediv">
27 <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>
29 <div class="refsynopsisdiv">
31 <div class="funcsynopsis">
32 <pre class="funcsynopsisinfo">
33 #include <lwres/lwbuffer.h>
35 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
37 <td><code class="funcdef">
39 <b class="fsfunc">lwres_buffer_init</b>(</code></td>
40 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
44 <td>void *<var class="pdparam">base</var>, </td>
48 <td>unsigned int <var class="pdparam">length</var><code>)</code>;</td>
51 <div class="funcprototype-spacer"> </div>
52 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
53 <td><code class="funcdef">
55 <b class="fsfunc">lwres_buffer_invalidate</b>(</code></td>
56 <td>lwres_buffer_t *<var class="pdparam">b</var><code>)</code>;</td>
58 <div class="funcprototype-spacer"> </div>
59 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
61 <td><code class="funcdef">
63 <b class="fsfunc">lwres_buffer_add</b>(</code></td>
64 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
68 <td>unsigned int <var class="pdparam">n</var><code>)</code>;</td>
71 <div class="funcprototype-spacer"> </div>
72 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
74 <td><code class="funcdef">
76 <b class="fsfunc">lwres_buffer_subtract</b>(</code></td>
77 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
81 <td>unsigned int <var class="pdparam">n</var><code>)</code>;</td>
84 <div class="funcprototype-spacer"> </div>
85 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
86 <td><code class="funcdef">
88 <b class="fsfunc">lwres_buffer_clear</b>(</code></td>
89 <td>lwres_buffer_t *<var class="pdparam">b</var><code>)</code>;</td>
91 <div class="funcprototype-spacer"> </div>
92 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
93 <td><code class="funcdef">
95 <b class="fsfunc">lwres_buffer_first</b>(</code></td>
96 <td>lwres_buffer_t *<var class="pdparam">b</var><code>)</code>;</td>
98 <div class="funcprototype-spacer"> </div>
99 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
101 <td><code class="funcdef">
103 <b class="fsfunc">lwres_buffer_forward</b>(</code></td>
104 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
108 <td>unsigned int <var class="pdparam">n</var><code>)</code>;</td>
111 <div class="funcprototype-spacer"> </div>
112 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
114 <td><code class="funcdef">
116 <b class="fsfunc">lwres_buffer_back</b>(</code></td>
117 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
121 <td>unsigned int <var class="pdparam">n</var><code>)</code>;</td>
124 <div class="funcprototype-spacer"> </div>
125 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
126 <td><code class="funcdef">
128 <b class="fsfunc">lwres_buffer_getuint8</b>(</code></td>
129 <td>lwres_buffer_t *<var class="pdparam">b</var><code>)</code>;</td>
131 <div class="funcprototype-spacer"> </div>
132 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
134 <td><code class="funcdef">
136 <b class="fsfunc">lwres_buffer_putuint8</b>(</code></td>
137 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
141 <td>lwres_uint8_t <var class="pdparam">val</var><code>)</code>;</td>
144 <div class="funcprototype-spacer"> </div>
145 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
146 <td><code class="funcdef">
148 <b class="fsfunc">lwres_buffer_getuint16</b>(</code></td>
149 <td>lwres_buffer_t *<var class="pdparam">b</var><code>)</code>;</td>
151 <div class="funcprototype-spacer"> </div>
152 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
154 <td><code class="funcdef">
156 <b class="fsfunc">lwres_buffer_putuint16</b>(</code></td>
157 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
161 <td>lwres_uint16_t <var class="pdparam">val</var><code>)</code>;</td>
164 <div class="funcprototype-spacer"> </div>
165 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr>
166 <td><code class="funcdef">
168 <b class="fsfunc">lwres_buffer_getuint32</b>(</code></td>
169 <td>lwres_buffer_t *<var class="pdparam">b</var><code>)</code>;</td>
171 <div class="funcprototype-spacer"> </div>
172 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
174 <td><code class="funcdef">
176 <b class="fsfunc">lwres_buffer_putuint32</b>(</code></td>
177 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
181 <td>lwres_uint32_t <var class="pdparam">val</var><code>)</code>;</td>
184 <div class="funcprototype-spacer"> </div>
185 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
187 <td><code class="funcdef">
189 <b class="fsfunc">lwres_buffer_putmem</b>(</code></td>
190 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
194 <td>const unsigned char *<var class="pdparam">base</var>, </td>
198 <td>unsigned int <var class="pdparam">length</var><code>)</code>;</td>
201 <div class="funcprototype-spacer"> </div>
202 <table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;">
204 <td><code class="funcdef">
206 <b class="fsfunc">lwres_buffer_getmem</b>(</code></td>
207 <td>lwres_buffer_t *<var class="pdparam">b</var>, </td>
211 <td>unsigned char *<var class="pdparam">base</var>, </td>
215 <td>unsigned int <var class="pdparam">length</var><code>)</code>;</td>
218 <div class="funcprototype-spacer"> </div>
221 <div class="refsection">
222 <a name="id-1.7"></a><h2>DESCRIPTION</h2>
224 These functions provide bounds checked access to a region of memory
225 where data is being read or written.
226 They are based on, and similar to, the
227 <code class="literal">isc_buffer_</code>
228 functions in the ISC library.
231 A buffer is a region of memory, together with a set of related
233 The <span class="emphasis"><em>used region</em></span> and the
234 <span class="emphasis"><em>available</em></span> region are disjoint, and
235 their union is the buffer's region.
236 The used region extends from the beginning of the buffer region to the
238 The available region extends from one byte greater than the last used
239 byte to the end of the buffer's region.
240 The size of the used region can be changed using various
242 Initially, the used region is empty.
245 The used region is further subdivided into two disjoint regions: the
246 <span class="emphasis"><em>consumed region</em></span> and the <span class="emphasis"><em>remaining region</em></span>.
247 The union of these two regions is the used region.
248 The consumed region extends from the beginning of the used region to
249 the byte before the <span class="emphasis"><em>current</em></span> offset (if any).
250 The <span class="emphasis"><em>remaining</em></span> region the current pointer to the end
253 The size of the consumed region can be changed using various
255 Initially, the consumed region is empty.
258 The <span class="emphasis"><em>active region</em></span> is an (optional) subregion of the
261 It extends from the current offset to an offset in the
263 Initially, the active region is empty.
264 If the current offset advances beyond the chosen offset,
265 the active region will also be empty.
267 <pre class="programlisting">
268 /------------entire length---------------\\
269 /----- used region -----\\/-- available --\\
270 +----------------------------------------+
271 | consumed | remaining | |
272 +----------------------------------------+
277 <pre class="programlisting">
279 b == current pointer. Can be anywhere between a and d.
280 c == active pointer. Meaningful between b and d.
282 e == length of buffer.
286 <pre class="programlisting">
287 a-e == entire length of buffer.
289 a-b == consumed region.
290 b-d == remaining region.
291 b-c == optional active region.
295 <p><code class="function">lwres_buffer_init()</code>
297 <span class="type">lwres_buffer_t</span>
298 <em class="parameter"><code>*b</code></em>
299 and assocates it with the memory region of size
300 <em class="parameter"><code>length</code></em>
301 bytes starting at location
302 <em class="parameter"><code>base.</code></em>
304 <p><code class="function">lwres_buffer_invalidate()</code>
305 marks the buffer <em class="parameter"><code>*b</code></em>
306 as invalid. Invalidating a buffer after use is not required,
307 but makes it possible to catch its possible accidental use.
311 <code class="function">lwres_buffer_add()</code>
313 <code class="function">lwres_buffer_subtract()</code>
314 respectively increase and decrease the used space in
316 <em class="parameter"><code>*b</code></em>
318 <em class="parameter"><code>n</code></em>
320 <code class="function">lwres_buffer_add()</code>
321 checks for buffer overflow and
322 <code class="function">lwres_buffer_subtract()</code>
323 checks for underflow.
324 These functions do not allocate or deallocate memory.
325 They just change the value of
326 <code class="varname">used</code>.
329 A buffer is re-initialised by
330 <code class="function">lwres_buffer_clear()</code>.
332 <code class="varname">used</code>,
333 <code class="varname">current</code>
335 <code class="varname">active</code>
338 <p><code class="function">lwres_buffer_first</code>
339 makes the consumed region of buffer
340 <em class="parameter"><code>*p</code></em>
342 <code class="varname">current</code>
343 to zero (the start of the buffer).
345 <p><code class="function">lwres_buffer_forward()</code>
346 increases the consumed region of buffer
347 <em class="parameter"><code>*b</code></em>
349 <em class="parameter"><code>n</code></em>
350 bytes, checking for overflow.
352 <code class="function">lwres_buffer_back()</code>
354 <em class="parameter"><code>b</code></em>'s
356 <em class="parameter"><code>n</code></em>
357 bytes and checks for underflow.
359 <p><code class="function">lwres_buffer_getuint8()</code>
360 reads an unsigned 8-bit integer from
361 <em class="parameter"><code>*b</code></em>
363 <code class="function">lwres_buffer_putuint8()</code>
364 writes the unsigned 8-bit integer
365 <em class="parameter"><code>val</code></em>
367 <em class="parameter"><code>*b</code></em>.
369 <p><code class="function">lwres_buffer_getuint16()</code>
371 <code class="function">lwres_buffer_getuint32()</code>
373 <code class="function">lwres_buffer_putuint8()</code>
374 except that they respectively read an unsigned 16-bit or 32-bit integer
375 in network byte order from
376 <em class="parameter"><code>b</code></em>.
378 <code class="function">lwres_buffer_putuint16()</code>
380 <code class="function">lwres_buffer_putuint32()</code>
381 writes the unsigned 16-bit or 32-bit integer
382 <em class="parameter"><code>val</code></em>
384 <em class="parameter"><code>b</code></em>,
385 in network byte order.
388 Arbitrary amounts of data are read or written from a lightweight
390 <code class="function">lwres_buffer_getmem()</code>
392 <code class="function">lwres_buffer_putmem()</code>
394 <code class="function">lwres_buffer_putmem()</code>
396 <em class="parameter"><code>length</code></em>
398 <em class="parameter"><code>base</code></em>
400 <em class="parameter"><code>b</code></em>.
402 <code class="function">lwres_buffer_getmem()</code>
404 <em class="parameter"><code>length</code></em>
406 <em class="parameter"><code>b</code></em>
408 <em class="parameter"><code>base</code></em>.