1 /* $NetBSD: ccmsg.h,v 1.4 2014/12/10 04:38:01 christos Exp $ */ 2 3 /* 4 * Portions Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 5 * Portions Copyright (C) 2001 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL 12 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 13 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY 14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 * 19 * Portions Copyright (C) 2001 Nominum, Inc. 20 * 21 * Permission to use, copy, modify, and/or distribute this software for any 22 * purpose with or without fee is hereby granted, provided that the above 23 * copyright notice and this permission notice appear in all copies. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NOMINUM DISCLAIMS ALL 26 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY 28 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 30 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 31 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 32 */ 33 34 /* Id: ccmsg.h,v 1.11 2007/08/28 07:20:43 tbox Exp */ 35 36 #ifndef ISCCC_CCMSG_H 37 #define ISCCC_CCMSG_H 1 38 39 /*! \file isccc/ccmsg.h */ 40 41 #include <isc/buffer.h> 42 #include <isc/lang.h> 43 #include <isc/socket.h> 44 45 /*% ISCCC Message Structure */ 46 typedef struct isccc_ccmsg { 47 /* private (don't touch!) */ 48 unsigned int magic; 49 isc_uint32_t size; 50 isc_buffer_t buffer; 51 unsigned int maxsize; 52 isc_mem_t *mctx; 53 isc_socket_t *sock; 54 isc_task_t *task; 55 isc_taskaction_t action; 56 void *arg; 57 isc_event_t event; 58 /* public (read-only) */ 59 isc_result_t result; 60 isc_sockaddr_t address; 61 } isccc_ccmsg_t; 62 63 ISC_LANG_BEGINDECLS 64 65 void 66 isccc_ccmsg_init(isc_mem_t *mctx, isc_socket_t *sock, isccc_ccmsg_t *ccmsg); 67 /*% 68 * Associate a cc message state with a given memory context and 69 * TCP socket. 70 * 71 * Requires: 72 * 73 *\li "mctx" and "sock" be non-NULL and valid types. 74 * 75 *\li "sock" be a read/write TCP socket. 76 * 77 *\li "ccmsg" be non-NULL and an uninitialized or invalidated structure. 78 * 79 * Ensures: 80 * 81 *\li "ccmsg" is a valid structure. 82 */ 83 84 void 85 isccc_ccmsg_setmaxsize(isccc_ccmsg_t *ccmsg, unsigned int maxsize); 86 /*% 87 * Set the maximum packet size to "maxsize" 88 * 89 * Requires: 90 * 91 *\li "ccmsg" be valid. 92 * 93 *\li 512 <= "maxsize" <= 4294967296 94 */ 95 96 isc_result_t 97 isccc_ccmsg_readmessage(isccc_ccmsg_t *ccmsg, 98 isc_task_t *task, isc_taskaction_t action, void *arg); 99 /*% 100 * Schedule an event to be delivered when a command channel message is 101 * readable, or when an error occurs on the socket. 102 * 103 * Requires: 104 * 105 *\li "ccmsg" be valid. 106 * 107 *\li "task", "taskaction", and "arg" be valid. 108 * 109 * Returns: 110 * 111 *\li #ISC_R_SUCCESS -- no error 112 *\li Anything that the isc_socket_recv() call can return. XXXMLG 113 * 114 * Notes: 115 * 116 *\li The event delivered is a fully generic event. It will contain no 117 * actual data. The sender will be a pointer to the isccc_ccmsg_t. 118 * The result code inside that structure should be checked to see 119 * what the final result was. 120 */ 121 122 void 123 isccc_ccmsg_cancelread(isccc_ccmsg_t *ccmsg); 124 /*% 125 * Cancel a readmessage() call. The event will still be posted with a 126 * CANCELED result code. 127 * 128 * Requires: 129 * 130 *\li "ccmsg" be valid. 131 */ 132 133 void 134 isccc_ccmsg_invalidate(isccc_ccmsg_t *ccmsg); 135 /*% 136 * Clean up all allocated state, and invalidate the structure. 137 * 138 * Requires: 139 * 140 *\li "ccmsg" be valid. 141 * 142 * Ensures: 143 * 144 *\li "ccmsg" is invalidated and disassociated with all memory contexts, 145 * sockets, etc. 146 */ 147 148 ISC_LANG_ENDDECLS 149 150 #endif /* ISCCC_CCMSG_H */ 151