1 /* $NetBSD: eventlib_p.h,v 1.1.1.1 2004/05/20 19:34:32 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (c) 1995-1999 by Internet Software Consortium 6 * 7 * Permission to use, copy, modify, and 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 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 14 * ANY 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 17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* eventlib_p.h - private interfaces for eventlib 21 * vix 09sep95 [initial] 22 * 23 * Id: eventlib_p.h,v 1.3.2.1.4.1 2004/03/09 08:33:43 marka Exp 24 */ 25 26 #ifndef _EVENTLIB_P_H 27 #define _EVENTLIB_P_H 28 29 #include <sys/param.h> 30 #include <sys/types.h> 31 #include <sys/socket.h> 32 #include <netinet/in.h> 33 #include <sys/un.h> 34 35 #define EVENTLIB_DEBUG 1 36 37 #include <errno.h> 38 #include <fcntl.h> 39 #include <stdio.h> 40 #include <stdlib.h> 41 #include <string.h> 42 43 #include <isc/heap.h> 44 #include <isc/list.h> 45 #include <isc/memcluster.h> 46 47 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) 48 #define EV_ERR(e) return (errno = (e), -1) 49 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL 50 51 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ 52 FILL(p); \ 53 else \ 54 (void)NULL; 55 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \ 56 errno = ENOMEM; \ 57 return (-1); \ 58 } else \ 59 FILL(p) 60 #define FREE(p) memput((p), sizeof *(p)) 61 62 #if EVENTLIB_DEBUG 63 #define FILL(p) memset((p), 0xF5, sizeof *(p)) 64 #else 65 #define FILL(p) 66 #endif 67 68 typedef struct evConn { 69 evConnFunc func; 70 void * uap; 71 int fd; 72 int flags; 73 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */ 74 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */ 75 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */ 76 evFileID file; 77 struct evConn * prev; 78 struct evConn * next; 79 } evConn; 80 81 typedef struct evAccept { 82 int fd; 83 union { 84 struct sockaddr sa; 85 struct sockaddr_in in; 86 #ifndef NO_SOCKADDR_UN 87 struct sockaddr_un un; 88 #endif 89 } la; 90 ISC_SOCKLEN_T lalen; 91 union { 92 struct sockaddr sa; 93 struct sockaddr_in in; 94 #ifndef NO_SOCKADDR_UN 95 struct sockaddr_un un; 96 #endif 97 } ra; 98 ISC_SOCKLEN_T ralen; 99 int ioErrno; 100 evConn * conn; 101 LINK(struct evAccept) link; 102 } evAccept; 103 104 typedef struct evFile { 105 evFileFunc func; 106 void * uap; 107 int fd; 108 int eventmask; 109 int preemptive; 110 struct evFile * prev; 111 struct evFile * next; 112 struct evFile * fdprev; 113 struct evFile * fdnext; 114 } evFile; 115 116 typedef struct evStream { 117 evStreamFunc func; 118 void * uap; 119 evFileID file; 120 evTimerID timer; 121 int flags; 122 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */ 123 int fd; 124 struct iovec * iovOrig; 125 int iovOrigCount; 126 struct iovec * iovCur; 127 int iovCurCount; 128 int ioTotal; 129 int ioDone; 130 int ioErrno; 131 struct evStream *prevDone, *nextDone; 132 struct evStream *prev, *next; 133 } evStream; 134 135 typedef struct evTimer { 136 evTimerFunc func; 137 void * uap; 138 struct timespec due, inter; 139 int index; 140 int mode; 141 #define EV_TMR_RATE 1 142 } evTimer; 143 144 typedef struct evWait { 145 evWaitFunc func; 146 void * uap; 147 const void * tag; 148 struct evWait * next; 149 } evWait; 150 151 typedef struct evWaitList { 152 evWait * first; 153 evWait * last; 154 struct evWaitList * prev; 155 struct evWaitList * next; 156 } evWaitList; 157 158 typedef struct evEvent_p { 159 enum { Accept, File, Stream, Timer, Wait, Free, Null } type; 160 union { 161 struct { evAccept *this; } accept; 162 struct { evFile *this; int eventmask; } file; 163 struct { evStream *this; } stream; 164 struct { evTimer *this; } timer; 165 struct { evWait *this; } wait; 166 struct { struct evEvent_p *next; } free; 167 struct { const void *placeholder; } null; 168 } u; 169 } evEvent_p; 170 171 typedef struct { 172 /* Global. */ 173 const evEvent_p *cur; 174 /* Debugging. */ 175 int debug; 176 FILE *output; 177 /* Connections. */ 178 evConn *conns; 179 LIST(evAccept) accepts; 180 /* Files. */ 181 evFile *files, *fdNext; 182 fd_set rdLast, rdNext; 183 fd_set wrLast, wrNext; 184 fd_set exLast, exNext; 185 fd_set nonblockBefore; 186 int fdMax, fdCount, highestFD; 187 evFile *fdTable[FD_SETSIZE]; 188 #ifdef EVENTLIB_TIME_CHECKS 189 struct timespec lastSelectTime; 190 int lastFdCount; 191 #endif 192 /* Streams. */ 193 evStream *streams; 194 evStream *strDone, *strLast; 195 /* Timers. */ 196 struct timespec lastEventTime; 197 heap_context timers; 198 /* Waits. */ 199 evWaitList *waitLists; 200 evWaitList waitDone; 201 } evContext_p; 202 203 /* eventlib.c */ 204 #define evPrintf __evPrintf 205 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...) 206 ISC_FORMAT_PRINTF(3, 4); 207 208 /* ev_timers.c */ 209 #define evCreateTimers __evCreateTimers 210 heap_context evCreateTimers(const evContext_p *); 211 #define evDestroyTimers __evDestroyTimers 212 void evDestroyTimers(const evContext_p *); 213 214 /* ev_waits.c */ 215 #define evFreeWait __evFreeWait 216 evWait *evFreeWait(evContext_p *ctx, evWait *old); 217 218 /* Global options */ 219 int __evOptMonoTime; 220 221 #endif /*_EVENTLIB_P_H*/ 222