Merge from vendor branch BZIP:
[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.10 2006/06/29 13:02:31 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.70.1">
23 </head>
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">
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>, </td>
53 </tr>
54 <tr>
55 <td> </td>
56 <td> </td>
57 <td>
58 <code>)</code>;</td>
59 </tr>
60 </table>
61 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
62 <tr>
63 <td><code class="funcdef">
64 void
65 <b class="fsfunc">lwres_buffer_invalidate</b>(</code></td>
66 <td> </td>
67 <td>
68 <code>)</code>;</td>
69 </tr>
70 <tr>
71 <td> </td>
72 <td> </td>
73 <td>
74 <code>)</code>;</td>
75 </tr>
76 </table>
77 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
78 <tr>
79 <td><code class="funcdef">
80 void
81 <b class="fsfunc">lwres_buffer_add</b>(</code></td>
82 <td> </td>
83 <td>, </td>
84 </tr>
85 <tr>
86 <td> </td>
87 <td> </td>
88 <td>, </td>
89 </tr>
90 <tr>
91 <td> </td>
92 <td> </td>
93 <td>
94 <code>)</code>;</td>
95 </tr>
96 </table>
97 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
98 <tr>
99 <td><code class="funcdef">
100 void
101 <b class="fsfunc">lwres_buffer_subtract</b>(</code></td>
102 <td> </td>
103 <td>, </td>
104 </tr>
105 <tr>
106 <td> </td>
107 <td> </td>
108 <td>, </td>
109 </tr>
110 <tr>
111 <td> </td>
112 <td> </td>
113 <td>
114 <code>)</code>;</td>
115 </tr>
116 </table>
117 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
118 <tr>
119 <td><code class="funcdef">
120 void
121 <b class="fsfunc">lwres_buffer_clear</b>(</code></td>
122 <td> </td>
123 <td>
124 <code>)</code>;</td>
125 </tr>
126 <tr>
127 <td> </td>
128 <td> </td>
129 <td>
130 <code>)</code>;</td>
131 </tr>
132 </table>
133 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
134 <tr>
135 <td><code class="funcdef">
136 void
137 <b class="fsfunc">lwres_buffer_first</b>(</code></td>
138 <td> </td>
139 <td>
140 <code>)</code>;</td>
141 </tr>
142 <tr>
143 <td> </td>
144 <td> </td>
145 <td>
146 <code>)</code>;</td>
147 </tr>
148 </table>
149 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
150 <tr>
151 <td><code class="funcdef">
152 void
153 <b class="fsfunc">lwres_buffer_forward</b>(</code></td>
154 <td> </td>
155 <td>, </td>
156 </tr>
157 <tr>
158 <td> </td>
159 <td> </td>
160 <td>, </td>
161 </tr>
162 <tr>
163 <td> </td>
164 <td> </td>
165 <td>
166 <code>)</code>;</td>
167 </tr>
168 </table>
169 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
170 <tr>
171 <td><code class="funcdef">
172 void
173 <b class="fsfunc">lwres_buffer_back</b>(</code></td>
174 <td> </td>
175 <td>, </td>
176 </tr>
177 <tr>
178 <td> </td>
179 <td> </td>
180 <td>, </td>
181 </tr>
182 <tr>
183 <td> </td>
184 <td> </td>
185 <td>
186 <code>)</code>;</td>
187 </tr>
188 </table>
189 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
190 <tr>
191 <td><code class="funcdef">
192 lwres_uint8_t
193 <b class="fsfunc">lwres_buffer_getuint8</b>(</code></td>
194 <td> </td>
195 <td>
196 <code>)</code>;</td>
197 </tr>
198 <tr>
199 <td> </td>
200 <td> </td>
201 <td>
202 <code>)</code>;</td>
203 </tr>
204 </table>
205 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
206 <tr>
207 <td><code class="funcdef">
208 void
209 <b class="fsfunc">lwres_buffer_putuint8</b>(</code></td>
210 <td> </td>
211 <td>, </td>
212 </tr>
213 <tr>
214 <td> </td>
215 <td> </td>
216 <td>, </td>
217 </tr>
218 <tr>
219 <td> </td>
220 <td> </td>
221 <td>
222 <code>)</code>;</td>
223 </tr>
224 </table>
225 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
226 <tr>
227 <td><code class="funcdef">
228 lwres_uint16_t
229 <b class="fsfunc">lwres_buffer_getuint16</b>(</code></td>
230 <td> </td>
231 <td>
232 <code>)</code>;</td>
233 </tr>
234 <tr>
235 <td> </td>
236 <td> </td>
237 <td>
238 <code>)</code>;</td>
239 </tr>
240 </table>
241 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
242 <tr>
243 <td><code class="funcdef">
244 void
245 <b class="fsfunc">lwres_buffer_putuint16</b>(</code></td>
246 <td> </td>
247 <td>, </td>
248 </tr>
249 <tr>
250 <td> </td>
251 <td> </td>
252 <td>, </td>
253 </tr>
254 <tr>
255 <td> </td>
256 <td> </td>
257 <td>
258 <code>)</code>;</td>
259 </tr>
260 </table>
261 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
262 <tr>
263 <td><code class="funcdef">
264 lwres_uint32_t
265 <b class="fsfunc">lwres_buffer_getuint32</b>(</code></td>
266 <td> </td>
267 <td>
268 <code>)</code>;</td>
269 </tr>
270 <tr>
271 <td> </td>
272 <td> </td>
273 <td>
274 <code>)</code>;</td>
275 </tr>
276 </table>
277 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
278 <tr>
279 <td><code class="funcdef">
280 void
281 <b class="fsfunc">lwres_buffer_putuint32</b>(</code></td>
282 <td> </td>
283 <td>, </td>
284 </tr>
285 <tr>
286 <td> </td>
287 <td> </td>
288 <td>, </td>
289 </tr>
290 <tr>
291 <td> </td>
292 <td> </td>
293 <td>
294 <code>)</code>;</td>
295 </tr>
296 </table>
297 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0" style="padding-bottom: 1em">
298 <tr>
299 <td><code class="funcdef">
300 void
301 <b class="fsfunc">lwres_buffer_putmem</b>(</code></td>
302 <td> </td>
303 <td>, </td>
304 </tr>
305 <tr>
306 <td> </td>
307 <td> </td>
308 <td>, </td>
309 </tr>
310 <tr>
311 <td> </td>
312 <td> </td>
313 <td>, </td>
314 </tr>
315 <tr>
316 <td> </td>
317 <td> </td>
318 <td>
319 <code>)</code>;</td>
320 </tr>
321 </table>
322 <table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0">
323 <tr>
324 <td><code class="funcdef">
325 void
326 <b class="fsfunc">lwres_buffer_getmem</b>(</code></td>
327 <td> </td>
328 <td>, </td>
329 </tr>
330 <tr>
331 <td> </td>
332 <td> </td>
333 <td>, </td>
334 </tr>
335 <tr>
336 <td> </td>
337 <td> </td>
338 <td>, </td>
339 </tr>
340 <tr>
341 <td> </td>
342 <td> </td>
343 <td>
344 <code>)</code>;</td>
345 </tr>
346 </table>
347 </div>
348 </div>
349 <div class="refsect1" lang="en">
350 <a name="id2549674"></a><h2>DESCRIPTION</h2>
351 <p>
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.
357 </p>
358 <p>
359 A buffer is a region of memory, together with a set of related
360 subregions.
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
365 last used byte.
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
369 buffer commands.
370 Initially, the used region is empty.
371 </p>
372 <p>
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
379 region.
380 The size of the consumed region can be changed using various
381 buffer commands.
382 Initially, the consumed region is empty.
383 </p>
384 <p>
385 The <span class="emphasis"><em>active region</em></span> is an (optional) subregion of the remaining
386 region.
387 It extends from the current offset to an offset in the
388 remaining region.
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.
392 </p>
393 <p>
394 </p>
395 <pre class="programlisting">
396  
397    /------------entire length---------------\\
398    /----- used region -----\\/-- available --\\
399    +----------------------------------------+
400    | consumed  | remaining |                |
401    +----------------------------------------+
402    a           b     c     d                e
403  
404   a == base of buffer.
405   b == current pointer.  Can be anywhere between a and d.
406   c == active pointer.  Meaningful between b and d.
407   d == used pointer.
408   e == length of buffer.
409  
410   a-e == entire length of buffer.
411   a-d == used region.
412   a-b == consumed region.
413   b-d == remaining region.
414   b-c == optional active region.
415 </pre>
416 <p>
417 </p>
418 <p>
419 <code class="function">lwres_buffer_init()</code>
420 initializes the
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>
427 </p>
428 <p>
429 <code class="function">lwres_buffer_invalidate()</code>
430 marks the buffer
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.
434 </p>
435 <p>
436 The functions
437 <code class="function">lwres_buffer_add()</code>
438 and
439 <code class="function">lwres_buffer_subtract()</code>
440 respectively increase and decrease the used space in
441 buffer
442 <em class="parameter"><code>*b</code></em>
443 by
444 <em class="parameter"><code>n</code></em>
445 bytes.
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>.
453 </p>
454 <p>
455 A buffer is re-initialised by
456 <code class="function">lwres_buffer_clear()</code>.
457 The function sets
458 <em class="structfield"><code>used</code></em> ,
459 <em class="structfield"><code>current</code></em>
460 and
461 <em class="structfield"><code>active</code></em>
462 to zero.
463 </p>
464 <p>
465 <code class="function">lwres_buffer_first</code>
466 makes the consumed region of buffer
467 <em class="parameter"><code>*p</code></em>
468 empty by setting
469 <em class="structfield"><code>current</code></em>
470 to zero (the start of the buffer).
471 </p>
472 <p>
473 <code class="function">lwres_buffer_forward()</code>
474 increases the consumed region of buffer
475 <em class="parameter"><code>*b</code></em>
476 by
477 <em class="parameter"><code>n</code></em>
478 bytes, checking for overflow.
479 Similarly,
480 <code class="function">lwres_buffer_back()</code>
481 decreases buffer
482 <em class="parameter"><code>b</code></em>'s
483 consumed region by
484 <em class="parameter"><code>n</code></em>
485 bytes and checks for underflow.
486 </p>
487 <p>
488 <code class="function">lwres_buffer_getuint8()</code>
489 reads an unsigned 8-bit integer from
490 <em class="parameter"><code>*b</code></em>
491 and returns it.
492 <code class="function">lwres_buffer_putuint8()</code>
493 writes the unsigned 8-bit integer
494 <em class="parameter"><code>val</code></em>
495 to buffer
496 <em class="parameter"><code>*b</code></em>.
497 </p>
498 <p>
499 <code class="function">lwres_buffer_getuint16()</code>
500 and
501 <code class="function">lwres_buffer_getuint32()</code>
502 are identical to
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>.
507 Similarly,
508 <code class="function">lwres_buffer_putuint16()</code>
509 and
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>
513 to buffer
514 <em class="parameter"><code>b</code></em>,
515 in network byte order.
516 </p>
517 <p>
518 Arbitrary amounts of data are read or written from a lightweight
519 resolver buffer with
520 <code class="function">lwres_buffer_getmem()</code>
521 and
522 <code class="function">lwres_buffer_putmem()</code>
523 respectively.
524 <code class="function">lwres_buffer_putmem()</code>
525 copies
526 <em class="parameter"><code>length</code></em>
527 bytes of memory at
528 <em class="parameter"><code>base</code></em>
529 to
530 <em class="parameter"><code>b</code></em>.
531 Conversely,
532 <code class="function">lwres_buffer_getmem()</code>
533 copies
534 <em class="parameter"><code>length</code></em>
535 bytes of memory from
536 <em class="parameter"><code>b</code></em>
537 to
538 <em class="parameter"><code>base</code></em>.
539 </p>
540 </div>
541 </div></body>
542 </html>