1 /* $NetBSD: buffer.h,v 1.1.1.3 2014/07/12 11:57:57 spz Exp $ */ 2 /* buffer.h 3 4 Definitions for the object management API protocol buffering... */ 5 6 /* 7 * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC") 8 * Copyright (c) 1996-2003 by Internet Software Consortium 9 * 10 * Permission to use, copy, modify, and distribute this software for any 11 * purpose with or without fee is hereby granted, provided that the above 12 * copyright notice and this permission notice appear in all copies. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 20 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 * 22 * Internet Systems Consortium, Inc. 23 * 950 Charter Street 24 * Redwood City, CA 94063 25 * <info@isc.org> 26 * https://www.isc.org/ 27 * 28 */ 29 30 /* OMAPI buffers are ring buffers, which means that the beginning of the 31 buffer and the end of the buffer chase each other around. As long as 32 the tail never catches up to the head, there's room in the buffer for 33 data. 34 35 - If the tail and the head are equal, the buffer is empty. 36 37 - If the tail is less than the head, the contents of the buffer 38 are the bytes from the head to the end of buffer, and in addition, 39 the bytes between the beginning of the buffer and the tail, not 40 including the byte addressed by the tail. 41 42 - If the tail is greater than the head, then the buffer contains 43 valid bytes starting with the byte addressed by the head, and 44 ending with the byte before the byte addressed by the tail. 45 46 There will always be at least one byte of waste, because the tail can't 47 increase so that it's equal to the head (that would represent an empty 48 buffer. */ 49 #define OMAPI_BUF_SIZE 4048 50 typedef struct _omapi_buffer { 51 struct _omapi_buffer *next; /* Buffers can be chained. */ 52 u_int32_t refcnt; /* Buffers are reference counted. */ 53 u_int16_t head, tail; /* Buffers are organized in a ring. */ 54 char buf [OMAPI_BUF_SIZE]; /* The actual buffer is included in 55 the buffer data structure. */ 56 } omapi_buffer_t; 57 58 #define BUFFER_BYTES_FREE(x) \ 59 ((x) -> tail > (x) -> head \ 60 ? sizeof ((x) -> buf) - ((x) -> tail - (x) -> head) \ 61 : (x) -> head - (x) -> tail) 62 63 #define BYTES_IN_BUFFER(x) \ 64 ((x) -> tail > (x) -> head \ 65 ? (x) -> tail - (x) -> head - 1 \ 66 : sizeof ((x) -> buf) - ((x) -> head - (x) -> tail) - 1) 67 68 isc_result_t omapi_connection_require (omapi_object_t *, unsigned); 69 isc_result_t omapi_connection_copyout (unsigned char *, 70 omapi_object_t *, unsigned); 71 isc_result_t omapi_connection_copyin (omapi_object_t *, 72 const unsigned char *, unsigned); 73 isc_result_t omapi_connection_flush (omapi_object_t *); 74 isc_result_t omapi_connection_get_uint32 (omapi_object_t *, u_int32_t *); 75 isc_result_t omapi_connection_put_uint32 (omapi_object_t *, u_int32_t); 76 isc_result_t omapi_connection_get_uint16 (omapi_object_t *, u_int16_t *); 77 isc_result_t omapi_connection_put_uint16 (omapi_object_t *, u_int32_t); 78 79