]> git.ipfire.org Git - thirdparty/dhcp.git/blob - includes/omapip/buffer.h
20149ee90a7541598860814d0437e4de31743344
[thirdparty/dhcp.git] / includes / omapip / buffer.h
1 /* buffer.h
2
3 Definitions for the object management API protocol buffering... */
4
5 /*
6 * Copyright (c) 1996-1999 Internet Software Consortium.
7 * Use is subject to license terms which appear in the file named
8 * ISC-LICENSE that should have accompanied this file when you
9 * received it. If a file named ISC-LICENSE did not accompany this
10 * file, or you are not sure the one you have is correct, you may
11 * obtain an applicable copy of the license at:
12 *
13 * http://www.isc.org/isc-license-1.0.html.
14 *
15 * This file is part of the ISC DHCP distribution. The documentation
16 * associated with this file is listed in the file DOCUMENTATION,
17 * included in the top-level directory of this release.
18 *
19 * Support and other services are available for ISC products - see
20 * http://www.isc.org for more information.
21 */
22
23 /* OMAPI buffers are ring buffers, which means that the beginning of the
24 buffer and the end of the buffer chase each other around. As long as
25 the tail never catches up to the head, there's room in the buffer for
26 data.
27
28 - If the tail and the head are equal, the buffer is empty.
29
30 - If the tail is less than the head, the contents of the buffer
31 are the bytes from the head to the end of buffer, and in addition,
32 the bytes between the beginning of the buffer and the tail, not
33 including the byte addressed by the tail.
34
35 - If the tail is greater than the head, then the buffer contains
36 valid bytes starting with the byte addressed by the head, and
37 ending with the byte before the byte addressed by the tail.
38
39 There will always be at least one byte of waste, because the tail can't
40 increase so that it's equal to the head (that would represent an empty
41 buffer. */
42 #define OMAPI_BUF_SIZE 4048
43 typedef struct _omapi_buffer {
44 struct _omapi_buffer *next; /* Buffers can be chained. */
45 u_int32_t refcnt; /* Buffers are reference counted. */
46 u_int16_t head, tail; /* Buffers are organized in a ring. */
47 char buf [OMAPI_BUF_SIZE]; /* The actual buffer is included in
48 the buffer data structure. */
49 } omapi_buffer_t;
50
51 #define BUFFER_BYTES_FREE(x) \
52 ((x) -> tail > (x) -> head \
53 ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \
54 : (x) -> head - (x) -> tail)
55
56 #define BYTES_IN_BUFFER(x) \
57 ((x) -> tail > (x) -> head \
58 ? (x) -> tail - (x) -> head - 1 \
59 : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1)
60
61 isc_result_t omapi_connection_require (omapi_object_t *, unsigned);
62 isc_result_t omapi_connection_copyout (unsigned char *,
63 omapi_object_t *, unsigned);
64 isc_result_t omapi_connection_copyin (omapi_object_t *,
65 const unsigned char *, unsigned);
66 isc_result_t omapi_connection_flush (omapi_object_t *);
67 isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *);
68 isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t);
69 isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *);
70 isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t);
71