includes/omapip/buffer.h

Go to the documentation of this file.
00001 /* buffer.h
00002 
00003    Definitions for the object management API protocol buffering... */
00004 
00005 /*
00006  * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
00007  * Copyright (c) 1996-2003 by Internet Software Consortium
00008  *
00009  * Permission to use, copy, modify, and distribute this software for any
00010  * purpose with or without fee is hereby granted, provided that the above
00011  * copyright notice and this permission notice appear in all copies.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
00014  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00015  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
00016  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00017  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00018  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00019  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00020  *
00021  *   Internet Systems Consortium, Inc.
00022  *   950 Charter Street
00023  *   Redwood City, CA 94063
00024  *   <info@isc.org>
00025  *   https://www.isc.org/
00026  *
00027  */
00028 
00029 /* OMAPI buffers are ring buffers, which means that the beginning of the
00030    buffer and the end of the buffer chase each other around.   As long as
00031    the tail never catches up to the head, there's room in the buffer for
00032    data.
00033 
00034         - If the tail and the head are equal, the buffer is empty.
00035 
00036         - If the tail is less than the head, the contents of the buffer
00037           are the bytes from the head to the end of buffer, and in addition,
00038           the bytes between the beginning of the buffer and the tail, not
00039           including the byte addressed by the tail.
00040 
00041         - If the tail is greater than the head, then the buffer contains
00042           valid bytes starting with the byte addressed by the head, and
00043           ending with the byte before the byte addressed by the tail.
00044 
00045    There will always be at least one byte of waste, because the tail can't
00046    increase so that it's equal to the head (that would represent an empty
00047    buffer. */
00048 #define OMAPI_BUF_SIZE 4048
00049 typedef struct _omapi_buffer {
00050         struct _omapi_buffer *next;     /* Buffers can be chained. */
00051         u_int32_t refcnt;               /* Buffers are reference counted. */
00052         u_int16_t head, tail;           /* Buffers are organized in a ring. */
00053         char buf [OMAPI_BUF_SIZE];      /* The actual buffer is included in
00054                                            the buffer data structure. */
00055 } omapi_buffer_t;       
00056 
00057 #define BUFFER_BYTES_FREE(x)    \
00058         ((x) -> tail > (x) -> head \
00059           ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \
00060           : (x) -> head - (x) -> tail)
00061 
00062 #define BYTES_IN_BUFFER(x)      \
00063         ((x) -> tail > (x) -> head \
00064          ? (x) -> tail - (x) -> head - 1 \
00065          : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1)
00066 
00067 isc_result_t omapi_connection_require (omapi_object_t *, unsigned);
00068 isc_result_t omapi_connection_copyout (unsigned char *,
00069                                        omapi_object_t *, unsigned);
00070 isc_result_t omapi_connection_copyin (omapi_object_t *,
00071                                       const unsigned char *, unsigned);
00072 isc_result_t omapi_connection_flush (omapi_object_t *);
00073 isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *);
00074 isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t);
00075 isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *);
00076 isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t);
00077 

Generated on 5 Apr 2014 for ISC DHCP by  doxygen 1.6.1