2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1995-1999 by Internet Software Consortium
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 /* eventlib_p.h - private interfaces for eventlib
19 * vix 09sep95 [initial]
21 * $Id: eventlib_p.h,v 1.3.2.2 2004/03/09 09:17:35 marka Exp $
27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
33 #define EVENTLIB_DEBUG 1
43 #include <isc/memcluster.h>
45 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
46 #define EV_ERR(e) return (errno = (e), -1)
47 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
49 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
53 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
58 #define FREE(p) memput((p), sizeof *(p))
61 #define FILL(p) memset((p), 0xF5, sizeof *(p))
66 typedef struct evConn {
71 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
72 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
73 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
79 typedef struct evAccept {
83 struct sockaddr_in in;
84 #ifndef NO_SOCKADDR_UN
85 struct sockaddr_un un;
91 struct sockaddr_in in;
92 #ifndef NO_SOCKADDR_UN
93 struct sockaddr_un un;
99 LINK(struct evAccept) link;
102 typedef struct evFile {
108 struct evFile * prev;
109 struct evFile * next;
110 struct evFile * fdprev;
111 struct evFile * fdnext;
114 typedef struct evStream {
120 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */
122 struct iovec * iovOrig;
124 struct iovec * iovCur;
129 struct evStream *prevDone, *nextDone;
130 struct evStream *prev, *next;
133 typedef struct evTimer {
136 struct timespec due, inter;
139 #define EV_TMR_RATE 1
142 typedef struct evWait {
146 struct evWait * next;
149 typedef struct evWaitList {
152 struct evWaitList * prev;
153 struct evWaitList * next;
156 typedef struct evEvent_p {
157 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
159 struct { evAccept *this; } accept;
160 struct { evFile *this; int eventmask; } file;
161 struct { evStream *this; } stream;
162 struct { evTimer *this; } timer;
163 struct { evWait *this; } wait;
164 struct { struct evEvent_p *next; } free;
165 struct { const void *placeholder; } null;
171 const evEvent_p *cur;
177 LIST(evAccept) accepts;
179 evFile *files, *fdNext;
180 fd_set rdLast, rdNext;
181 fd_set wrLast, wrNext;
182 fd_set exLast, exNext;
183 fd_set nonblockBefore;
184 int fdMax, fdCount, highestFD;
185 evFile *fdTable[FD_SETSIZE];
186 #ifdef EVENTLIB_TIME_CHECKS
187 struct timespec lastSelectTime;
192 evStream *strDone, *strLast;
194 struct timespec lastEventTime;
197 evWaitList *waitLists;
202 #define evPrintf __evPrintf
203 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
204 ISC_FORMAT_PRINTF(3, 4);
207 #define evCreateTimers __evCreateTimers
208 heap_context evCreateTimers(const evContext_p *);
209 #define evDestroyTimers __evDestroyTimers
210 void evDestroyTimers(const evContext_p *);
213 #define evFreeWait __evFreeWait
214 evWait *evFreeWait(evContext_p *ctx, evWait *old);
219 #endif /*_EVENTLIB_P_H*/