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