/contrib/bind9/lib/lwres/man/lwres_buffer.3

https://bitbucket.org/freebsd/freebsd-head/ · Unknown · 233 lines · 233 code · 0 blank · 0 comment · 0 complexity · d1fd97d1a46890c399adbf8f08f15b90 MD5 · raw file

  1. .\" Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
  2. .\" Copyright (C) 2000, 2001 Internet Software Consortium.
  3. .\"
  4. .\" Permission to use, copy, modify, and/or distribute this software for any
  5. .\" purpose with or without fee is hereby granted, provided that the above
  6. .\" copyright notice and this permission notice appear in all copies.
  7. .\"
  8. .\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. .\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. .\" AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. .\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. .\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. .\" PERFORMANCE OF THIS SOFTWARE.
  15. .\"
  16. .\" $Id$
  17. .\"
  18. .hy 0
  19. .ad l
  20. .\" Title: lwres_buffer
  21. .\" Author:
  22. .\" Generator: DocBook XSL Stylesheets v1.71.1 <http://docbook.sf.net/>
  23. .\" Date: Jun 30, 2000
  24. .\" Manual: BIND9
  25. .\" Source: BIND9
  26. .\"
  27. .TH "LWRES_BUFFER" "3" "Jun 30, 2000" "BIND9" "BIND9"
  28. .\" disable hyphenation
  29. .nh
  30. .\" disable justification (adjust text to left margin only)
  31. .ad l
  32. .SH "NAME"
  33. 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
  34. .SH "SYNOPSIS"
  35. .nf
  36. #include <lwres/lwbuffer.h>
  37. .fi
  38. .HP 23
  39. .BI "void lwres_buffer_init(lwres_buffer_t\ *" "b" ", void\ *" "base" ", unsigned\ int\ " "length" ");"
  40. .HP 29
  41. .BI "void lwres_buffer_invalidate(lwres_buffer_t\ *" "b" ");"
  42. .HP 22
  43. .BI "void lwres_buffer_add(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
  44. .HP 27
  45. .BI "void lwres_buffer_subtract(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
  46. .HP 24
  47. .BI "void lwres_buffer_clear(lwres_buffer_t\ *" "b" ");"
  48. .HP 24
  49. .BI "void lwres_buffer_first(lwres_buffer_t\ *" "b" ");"
  50. .HP 26
  51. .BI "void lwres_buffer_forward(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
  52. .HP 23
  53. .BI "void lwres_buffer_back(lwres_buffer_t\ *" "b" ", unsigned\ int\ " "n" ");"
  54. .HP 36
  55. .BI "lwres_uint8_t lwres_buffer_getuint8(lwres_buffer_t\ *" "b" ");"
  56. .HP 27
  57. .BI "void lwres_buffer_putuint8(lwres_buffer_t\ *" "b" ", lwres_uint8_t\ " "val" ");"
  58. .HP 38
  59. .BI "lwres_uint16_t lwres_buffer_getuint16(lwres_buffer_t\ *" "b" ");"
  60. .HP 28
  61. .BI "void lwres_buffer_putuint16(lwres_buffer_t\ *" "b" ", lwres_uint16_t\ " "val" ");"
  62. .HP 38
  63. .BI "lwres_uint32_t lwres_buffer_getuint32(lwres_buffer_t\ *" "b" ");"
  64. .HP 28
  65. .BI "void lwres_buffer_putuint32(lwres_buffer_t\ *" "b" ", lwres_uint32_t\ " "val" ");"
  66. .HP 25
  67. .BI "void lwres_buffer_putmem(lwres_buffer_t\ *" "b" ", const\ unsigned\ char\ *" "base" ", unsigned\ int\ " "length" ");"
  68. .HP 25
  69. .BI "void lwres_buffer_getmem(lwres_buffer_t\ *" "b" ", unsigned\ char\ *" "base" ", unsigned\ int\ " "length" ");"
  70. .SH "DESCRIPTION"
  71. .PP
  72. These functions provide bounds checked access to a region of memory where data is being read or written. They are based on, and similar to, the
  73. isc_buffer_
  74. functions in the ISC library.
  75. .PP
  76. A buffer is a region of memory, together with a set of related subregions. The
  77. \fIused region\fR
  78. and the
  79. \fIavailable\fR
  80. region are disjoint, and their union is the buffer's region. The used region extends from the beginning of the buffer region to the last used byte. The available region extends from one byte greater than the last used byte to the end of the buffer's region. The size of the used region can be changed using various buffer commands. Initially, the used region is empty.
  81. .PP
  82. The used region is further subdivided into two disjoint regions: the
  83. \fIconsumed region\fR
  84. and the
  85. \fIremaining region\fR. The union of these two regions is the used region. The consumed region extends from the beginning of the used region to the byte before the
  86. \fIcurrent\fR
  87. offset (if any). The
  88. \fIremaining\fR
  89. region the current pointer to the end of the used region. The size of the consumed region can be changed using various buffer commands. Initially, the consumed region is empty.
  90. .PP
  91. The
  92. \fIactive region\fR
  93. is an (optional) subregion of the remaining region. It extends from the current offset to an offset in the remaining region. Initially, the active region is empty. If the current offset advances beyond the chosen offset, the active region will also be empty.
  94. .PP
  95. .RS 4
  96. .nf
  97. /\-\-\-\-\-\-\-\-\-\-\-\-entire length\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\\\\
  98. /\-\-\-\-\- used region \-\-\-\-\-\\\\/\-\- available \-\-\\\\
  99. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  100. | consumed | remaining | |
  101. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  102. a b c d e
  103. .fi
  104. .RE
  105. .sp
  106. .PP
  107. .RS 4
  108. .nf
  109. a == base of buffer.
  110. b == current pointer. Can be anywhere between a and d.
  111. c == active pointer. Meaningful between b and d.
  112. d == used pointer.
  113. e == length of buffer.
  114. .fi
  115. .RE
  116. .sp
  117. .PP
  118. .RS 4
  119. .nf
  120. a\-e == entire length of buffer.
  121. a\-d == used region.
  122. a\-b == consumed region.
  123. b\-d == remaining region.
  124. b\-c == optional active region.
  125. .fi
  126. .RE
  127. .sp
  128. .PP
  129. \fBlwres_buffer_init()\fR
  130. initializes the
  131. \fBlwres_buffer_t\fR
  132. \fI*b\fR
  133. and assocates it with the memory region of size
  134. \fIlength\fR
  135. bytes starting at location
  136. \fIbase.\fR
  137. .PP
  138. \fBlwres_buffer_invalidate()\fR
  139. marks the buffer
  140. \fI*b\fR
  141. as invalid. Invalidating a buffer after use is not required, but makes it possible to catch its possible accidental use.
  142. .PP
  143. The functions
  144. \fBlwres_buffer_add()\fR
  145. and
  146. \fBlwres_buffer_subtract()\fR
  147. respectively increase and decrease the used space in buffer
  148. \fI*b\fR
  149. by
  150. \fIn\fR
  151. bytes.
  152. \fBlwres_buffer_add()\fR
  153. checks for buffer overflow and
  154. \fBlwres_buffer_subtract()\fR
  155. checks for underflow. These functions do not allocate or deallocate memory. They just change the value of
  156. used.
  157. .PP
  158. A buffer is re\-initialised by
  159. \fBlwres_buffer_clear()\fR. The function sets
  160. used,
  161. current
  162. and
  163. active
  164. to zero.
  165. .PP
  166. \fBlwres_buffer_first\fR
  167. makes the consumed region of buffer
  168. \fI*p\fR
  169. empty by setting
  170. current
  171. to zero (the start of the buffer).
  172. .PP
  173. \fBlwres_buffer_forward()\fR
  174. increases the consumed region of buffer
  175. \fI*b\fR
  176. by
  177. \fIn\fR
  178. bytes, checking for overflow. Similarly,
  179. \fBlwres_buffer_back()\fR
  180. decreases buffer
  181. \fIb\fR's consumed region by
  182. \fIn\fR
  183. bytes and checks for underflow.
  184. .PP
  185. \fBlwres_buffer_getuint8()\fR
  186. reads an unsigned 8\-bit integer from
  187. \fI*b\fR
  188. and returns it.
  189. \fBlwres_buffer_putuint8()\fR
  190. writes the unsigned 8\-bit integer
  191. \fIval\fR
  192. to buffer
  193. \fI*b\fR.
  194. .PP
  195. \fBlwres_buffer_getuint16()\fR
  196. and
  197. \fBlwres_buffer_getuint32()\fR
  198. are identical to
  199. \fBlwres_buffer_putuint8()\fR
  200. except that they respectively read an unsigned 16\-bit or 32\-bit integer in network byte order from
  201. \fIb\fR. Similarly,
  202. \fBlwres_buffer_putuint16()\fR
  203. and
  204. \fBlwres_buffer_putuint32()\fR
  205. writes the unsigned 16\-bit or 32\-bit integer
  206. \fIval\fR
  207. to buffer
  208. \fIb\fR, in network byte order.
  209. .PP
  210. Arbitrary amounts of data are read or written from a lightweight resolver buffer with
  211. \fBlwres_buffer_getmem()\fR
  212. and
  213. \fBlwres_buffer_putmem()\fR
  214. respectively.
  215. \fBlwres_buffer_putmem()\fR
  216. copies
  217. \fIlength\fR
  218. bytes of memory at
  219. \fIbase\fR
  220. to
  221. \fIb\fR. Conversely,
  222. \fBlwres_buffer_getmem()\fR
  223. copies
  224. \fIlength\fR
  225. bytes of memory from
  226. \fIb\fR
  227. to
  228. \fIbase\fR.
  229. .SH "COPYRIGHT"
  230. Copyright \(co 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
  231. .br
  232. Copyright \(co 2000, 2001 Internet Software Consortium.
  233. .br