2 * Copyright (c) 2005 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.1.4.4 2006/03/10 00:17:21 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
48 #define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \
51 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
55 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
60 #define FREE(p) memput((p), sizeof *(p))
63 #define FILL(p) memset((p), 0xF5, sizeof *(p))
75 typedef struct evConn {
80 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
81 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
82 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
88 typedef struct evAccept {
92 struct sockaddr_in in;
93 #ifndef NO_SOCKADDR_UN
94 struct sockaddr_un un;
100 struct sockaddr_in in;
101 #ifndef NO_SOCKADDR_UN
102 struct sockaddr_un un;
108 LINK(struct evAccept) link;
111 typedef struct evFile {
117 struct evFile * prev;
118 struct evFile * next;
119 struct evFile * fdprev;
120 struct evFile * fdnext;
123 typedef struct evStream {
129 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */
131 struct iovec * iovOrig;
133 struct iovec * iovCur;
138 struct evStream *prevDone, *nextDone;
139 struct evStream *prev, *next;
142 typedef struct evTimer {
145 struct timespec due, inter;
148 #define EV_TMR_RATE 1
151 typedef struct evWait {
155 struct evWait * next;
158 typedef struct evWaitList {
161 struct evWaitList * prev;
162 struct evWaitList * next;
165 typedef struct evEvent_p {
166 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
168 struct { evAccept *this; } accept;
169 struct { evFile *this; int eventmask; } file;
170 struct { evStream *this; } stream;
171 struct { evTimer *this; } timer;
172 struct { evWait *this; } wait;
173 struct { struct evEvent_p *next; } free;
174 struct { const void *placeholder; } null;
180 void *ctx; /* pointer to the evContext_p */
181 uint32_t type; /* READ, WRITE, EXCEPT, nonblk */
182 uint32_t result; /* 1 => revents, 0 => events */
185 #define emulMaskInit(ctx, field, ev, lastnext) \
186 ctx->field.ctx = ctx; \
187 ctx->field.type = ev; \
188 ctx->field.result = lastnext;
190 extern short *__fd_eventfield(int fd, __evEmulMask *maskp);
191 extern short __poll_event(__evEmulMask *maskp);
192 extern void __fd_clr(int fd, __evEmulMask *maskp);
193 extern void __fd_set(int fd, __evEmulMask *maskp);
196 #define FD_ZERO(maskp)
199 #define FD_SET(fd, maskp) \
203 #define FD_CLR(fd, maskp) \
207 #define FD_ISSET(fd, maskp) \
208 ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
210 #endif /* USE_POLL */
214 const evEvent_p *cur;
220 LIST(evAccept) accepts;
222 evFile *files, *fdNext;
224 fd_set rdLast, rdNext;
225 fd_set wrLast, wrNext;
226 fd_set exLast, exNext;
227 fd_set nonblockBefore;
228 int fdMax, fdCount, highestFD;
229 evFile *fdTable[FD_SETSIZE];
231 struct pollfd *pollfds; /* Allocated as needed */
232 evFile **fdTable; /* Ditto */
233 int maxnfds; /* # elements in above */
234 int firstfd; /* First active fd */
235 int fdMax; /* Last active fd */
236 int fdCount; /* # fd:s with I/O */
237 int highestFD; /* max fd allowed by OS */
238 __evEmulMask rdLast, rdNext;
239 __evEmulMask wrLast, wrNext;
240 __evEmulMask exLast, exNext;
241 __evEmulMask nonblockBefore;
242 #endif /* USE_POLL */
243 #ifdef EVENTLIB_TIME_CHECKS
244 struct timespec lastSelectTime;
249 evStream *strDone, *strLast;
251 struct timespec lastEventTime;
254 evWaitList *waitLists;
259 #define evPrintf __evPrintf
260 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
261 ISC_FORMAT_PRINTF(3, 4);
264 extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd);
265 #endif /* USE_POLL */
268 #define evCreateTimers __evCreateTimers
269 heap_context evCreateTimers(const evContext_p *);
270 #define evDestroyTimers __evDestroyTimers
271 void evDestroyTimers(const evContext_p *);
274 #define evFreeWait __evFreeWait
275 evWait *evFreeWait(evContext_p *ctx, evWait *old);
278 extern int __evOptMonoTime;
280 #endif /*_EVENTLIB_P_H*/