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