Merge from vendor branch FILE:
[dragonfly.git] / contrib / bind-9.3 / lib / lwres / man / lwres_buffer.html
1 <!--
2  - Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3  - Copyright (C) 2000, 2001 Internet Software Consortium.
4  - 
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.
8  - 
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.
16 -->
17 <!-- $Id: lwres_buffer.html,v 1.4.2.1.4.8 2005/10/13 02:33:55 marka Exp $ -->
18 <html>
19 <head>
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">
23 </head>
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">
27 <h2>Name</h2>
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 &#8212; lightweight resolver buffer management</p>
29 </div>
30 <div class="refsynopsisdiv">
31 <h2>Synopsis</h2>
32 <div class="funcsynopsis">
33 <pre class="funcsynopsisinfo">
34 #include &lt;lwres/lwbuffer.h&gt;
35 </pre>
36 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
37 <tr>
38 <td><code class="funcdef">
39 void
40 <b class="fsfunc">lwres_buffer_init</b>(</code></td>
41 <td> </td>
42 <td>, </td>
43 </tr>
44 <tr>
45 <td> </td>
46 <td> </td>
47 <td>, </td>
48 </tr>
49 <tr>
50 <td> </td>
51 <td> </td>
52 <td>
53 <code>)</code>;</td>
54 </tr>
55 </table>
56 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
57 <td><code class="funcdef">
58 void
59 <b class="fsfunc">lwres_buffer_invalidate</b>(</code></td>
60 <td> </td>
61 <td>
62 <code>)</code>;</td>
63 </tr></table>
64 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
65 <tr>
66 <td><code class="funcdef">
67 void
68 <b class="fsfunc">lwres_buffer_add</b>(</code></td>
69 <td> </td>
70 <td>, </td>
71 </tr>
72 <tr>
73 <td> </td>
74 <td> </td>
75 <td>
76 <code>)</code>;</td>
77 </tr>
78 </table>
79 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
80 <tr>
81 <td><code class="funcdef">
82 void
83 <b class="fsfunc">lwres_buffer_subtract</b>(</code></td>
84 <td> </td>
85 <td>, </td>
86 </tr>
87 <tr>
88 <td> </td>
89 <td> </td>
90 <td>
91 <code>)</code>;</td>
92 </tr>
93 </table>
94 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
95 <td><code class="funcdef">
96 void
97 <b class="fsfunc">lwres_buffer_clear</b>(</code></td>
98 <td> </td>
99 <td>
100 <code>)</code>;</td>
101 </tr></table>
102 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
103 <td><code class="funcdef">
104 void
105 <b class="fsfunc">lwres_buffer_first</b>(</code></td>
106 <td> </td>
107 <td>
108 <code>)</code>;</td>
109 </tr></table>
110 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
111 <tr>
112 <td><code class="funcdef">
113 void
114 <b class="fsfunc">lwres_buffer_forward</b>(</code></td>
115 <td> </td>
116 <td>, </td>
117 </tr>
118 <tr>
119 <td> </td>
120 <td> </td>
121 <td>
122 <code>)</code>;</td>
123 </tr>
124 </table>
125 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
126 <tr>
127 <td><code class="funcdef">
128 void
129 <b class="fsfunc">lwres_buffer_back</b>(</code></td>
130 <td> </td>
131 <td>, </td>
132 </tr>
133 <tr>
134 <td> </td>
135 <td> </td>
136 <td>
137 <code>)</code>;</td>
138 </tr>
139 </table>
140 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
141 <td><code class="funcdef">
142 lwres_uint8_t
143 <b class="fsfunc">lwres_buffer_getuint8</b>(</code></td>
144 <td> </td>
145 <td>
146 <code>)</code>;</td>
147 </tr></table>
148 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
149 <tr>
150 <td><code class="funcdef">
151 void
152 <b class="fsfunc">lwres_buffer_putuint8</b>(</code></td>
153 <td> </td>
154 <td>, </td>
155 </tr>
156 <tr>
157 <td> </td>
158 <td> </td>
159 <td>
160 <code>)</code>;</td>
161 </tr>
162 </table>
163 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
164 <td><code class="funcdef">
165 lwres_uint16_t
166 <b class="fsfunc">lwres_buffer_getuint16</b>(</code></td>
167 <td> </td>
168 <td>
169 <code>)</code>;</td>
170 </tr></table>
171 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
172 <tr>
173 <td><code class="funcdef">
174 void
175 <b class="fsfunc">lwres_buffer_putuint16</b>(</code></td>
176 <td> </td>
177 <td>, </td>
178 </tr>
179 <tr>
180 <td> </td>
181 <td> </td>
182 <td>
183 <code>)</code>;</td>
184 </tr>
185 </table>
186 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em"><tr>
187 <td><code class="funcdef">
188 lwres_uint32_t
189 <b class="fsfunc">lwres_buffer_getuint32</b>(</code></td>
190 <td> </td>
191 <td>
192 <code>)</code>;</td>
193 </tr></table>
194 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
195 <tr>
196 <td><code class="funcdef">
197 void
198 <b class="fsfunc">lwres_buffer_putuint32</b>(</code></td>
199 <td> </td>
200 <td>, </td>
201 </tr>
202 <tr>
203 <td> </td>
204 <td> </td>
205 <td>
206 <code>)</code>;</td>
207 </tr>
208 </table>
209 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
210 <tr>
211 <td><code class="funcdef">
212 void
213 <b class="fsfunc">lwres_buffer_putmem</b>(</code></td>
214 <td> </td>
215 <td>, </td>
216 </tr>
217 <tr>
218 <td> </td>
219 <td> </td>
220 <td>, </td>
221 </tr>
222 <tr>
223 <td> </td>
224 <td> </td>
225 <td>
226 <code>)</code>;</td>
227 </tr>
228 </table>
229 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
230 <tr>
231 <td><code class="funcdef">
232 void
233 <b class="fsfunc">lwres_buffer_getmem</b>(</code></td>
234 <td> </td>
235 <td>, </td>
236 </tr>
237 <tr>
238 <td> </td>
239 <td> </td>
240 <td>, </td>
241 </tr>
242 <tr>
243 <td> </td>
244 <td> </td>
245 <td>
246 <code>)</code>;</td>
247 </tr>
248 </table>
249 </div>
250 </div>
251 <div class="refsect1" lang="en">
252 <a name="id2526109"></a><h2>DESCRIPTION</h2>
253 <p>
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.
259 </p>
260 <p>
261 A buffer is a region of memory, together with a set of related
262 subregions.
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
267 last used byte.
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
271 buffer commands.
272 Initially, the used region is empty.
273 </p>
274 <p>
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
281 region.
282 The size of the consumed region can be changed using various
283 buffer commands.
284 Initially, the consumed region is empty.
285 </p>
286 <p>
287 The <span class="emphasis"><em>active region</em></span> is an (optional) subregion of the remaining
288 region.
289 It extends from the current offset to an offset in the
290 remaining region.
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.
294 </p>
295 <p>
296 </p>
297 <pre class="programlisting">
298  
299    /------------entire length---------------\\
300    /----- used region -----\\/-- available --\\
301    +----------------------------------------+
302    | consumed  | remaining |                |
303    +----------------------------------------+
304    a           b     c     d                e
305  
306   a == base of buffer.
307   b == current pointer.  Can be anywhere between a and d.
308   c == active pointer.  Meaningful between b and d.
309   d == used pointer.
310   e == length of buffer.
311  
312   a-e == entire length of buffer.
313   a-d == used region.
314   a-b == consumed region.
315   b-d == remaining region.
316   b-c == optional active region.
317 </pre>
318 <p>
319 </p>
320 <p>
321 <code class="function">lwres_buffer_init()</code>
322 initializes the
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>
329 </p>
330 <p>
331 <code class="function">lwres_buffer_invalidate()</code>
332 marks the buffer
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.
336 </p>
337 <p>
338 The functions
339 <code class="function">lwres_buffer_add()</code>
340 and
341 <code class="function">lwres_buffer_subtract()</code>
342 respectively increase and decrease the used space in
343 buffer
344 <em class="parameter"><code>*b</code></em>
345 by
346 <em class="parameter"><code>n</code></em>
347 bytes.
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>.
355 </p>
356 <p>
357 A buffer is re-initialised by
358 <code class="function">lwres_buffer_clear()</code>.
359 The function sets
360 <em class="structfield"><code>used</code></em> ,
361 <em class="structfield"><code>current</code></em>
362 and
363 <em class="structfield"><code>active</code></em>
364 to zero.
365 </p>
366 <p>
367 <code class="function">lwres_buffer_first</code>
368 makes the consumed region of buffer
369 <em class="parameter"><code>*p</code></em>
370 empty by setting
371 <em class="structfield"><code>current</code></em>
372 to zero (the start of the buffer).
373 </p>
374 <p>
375 <code class="function">lwres_buffer_forward()</code>
376 increases the consumed region of buffer
377 <em class="parameter"><code>*b</code></em>
378 by
379 <em class="parameter"><code>n</code></em>
380 bytes, checking for overflow.
381 Similarly,
382 <code class="function">lwres_buffer_back()</code>
383 decreases buffer
384 <em class="parameter"><code>b</code></em>'s
385 consumed region by
386 <em class="parameter"><code>n</code></em>
387 bytes and checks for underflow.
388 </p>
389 <p>
390 <code class="function">lwres_buffer_getuint8()</code>
391 reads an unsigned 8-bit integer from
392 <em class="parameter"><code>*b</code></em>
393 and returns it.
394 <code class="function">lwres_buffer_putuint8()</code>
395 writes the unsigned 8-bit integer
396 <em class="parameter"><code>val</code></em>
397 to buffer
398 <em class="parameter"><code>*b</code></em>.
399 </p>
400 <p>
401 <code class="function">lwres_buffer_getuint16()</code>
402 and
403 <code class="function">lwres_buffer_getuint32()</code>
404 are identical to
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>.
409 Similarly,
410 <code class="function">lwres_buffer_putuint16()</code>
411 and
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>
415 to buffer
416 <em class="parameter"><code>b</code></em>,
417 in network byte order.
418 </p>
419 <p>
420 Arbitrary amounts of data are read or written from a lightweight
421 resolver buffer with
422 <code class="function">lwres_buffer_getmem()</code>
423 and
424 <code class="function">lwres_buffer_putmem()</code>
425 respectively.
426 <code class="function">lwres_buffer_putmem()</code>
427 copies
428 <em class="parameter"><code>length</code></em>
429 bytes of memory at
430 <em class="parameter"><code>base</code></em>
431 to
432 <em class="parameter"><code>b</code></em>.
433 Conversely,
434 <code class="function">lwres_buffer_getmem()</code>
435 copies
436 <em class="parameter"><code>length</code></em>
437 bytes of memory from
438 <em class="parameter"><code>b</code></em>
439 to
440 <em class="parameter"><code>base</code></em>.
441 </p>
442 </div>
443 </div></body>
444 </html>