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.
19 * \brief private interfaces for eventlib
20 * \author vix 09sep95 [initial]
22 * $Id: eventlib_p.h,v 1.5.18.4 2006/03/10 00:20:08 marka Exp $
29 #include <sys/param.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
35 #define EVENTLIB_DEBUG 1
46 #include <isc/memcluster.h>
49 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
50 #define EV_ERR(e) return (errno = (e), -1)
51 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
52 #define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \
55 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
59 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
64 #define FREE(p) memput((p), sizeof *(p))
67 #define FILL(p) memset((p), 0xF5, sizeof *(p))
79 typedef struct evConn {
84 #define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */
85 #define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */
86 #define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */
93 typedef struct evAccept {
97 struct sockaddr_in in;
98 #ifndef NO_SOCKADDR_UN
99 struct sockaddr_un un;
105 struct sockaddr_in in;
106 #ifndef NO_SOCKADDR_UN
107 struct sockaddr_un un;
113 LINK(struct evAccept) link;
116 typedef struct evFile {
122 struct evFile * prev;
123 struct evFile * next;
124 struct evFile * fdprev;
125 struct evFile * fdnext;
128 typedef struct evStream {
134 #define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */
136 struct iovec * iovOrig;
138 struct iovec * iovCur;
143 struct evStream *prevDone, *nextDone;
144 struct evStream *prev, *next;
147 typedef struct evTimer {
150 struct timespec due, inter;
153 #define EV_TMR_RATE 1
156 typedef struct evWait {
160 struct evWait * next;
163 typedef struct evWaitList {
166 struct evWaitList * prev;
167 struct evWaitList * next;
170 typedef struct evEvent_p {
171 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
173 struct { evAccept *this; } accept;
174 struct { evFile *this; int eventmask; } file;
175 struct { evStream *this; } stream;
176 struct { evTimer *this; } timer;
177 struct { evWait *this; } wait;
178 struct { struct evEvent_p *next; } free;
179 struct { const void *placeholder; } null;
186 void *ctx; /* pointer to the evContext_p */
187 uint32_t type; /* READ, WRITE, EXCEPT, nonblk */
188 uint32_t result; /* 1 => revents, 0 => events */
191 #define emulMaskInit(ctx, field, ev, lastnext) \
192 ctx->field.ctx = ctx; \
193 ctx->field.type = ev; \
194 ctx->field.result = lastnext;
196 extern short *__fd_eventfield(int fd, __evEmulMask *maskp);
197 extern short __poll_event(__evEmulMask *maskp);
198 extern void __fd_clr(int fd, __evEmulMask *maskp);
199 extern void __fd_set(int fd, __evEmulMask *maskp);
202 #define FD_ZERO(maskp)
205 #define FD_SET(fd, maskp) \
209 #define FD_CLR(fd, maskp) \
213 #define FD_ISSET(fd, maskp) \
214 ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
216 #endif /* USE_POLL */
221 const evEvent_p *cur;
227 LIST(evAccept) accepts;
229 evFile *files, *fdNext;
231 fd_set rdLast, rdNext;
232 fd_set wrLast, wrNext;
233 fd_set exLast, exNext;
234 fd_set nonblockBefore;
235 int fdMax, fdCount, highestFD;
236 evFile *fdTable[FD_SETSIZE];
238 struct pollfd *pollfds; /* Allocated as needed */
239 evFile **fdTable; /* Ditto */
240 int maxnfds; /* # elements in above */
241 int firstfd; /* First active fd */
242 int fdMax; /* Last active fd */
243 int fdCount; /* # fd:s with I/O */
244 int highestFD; /* max fd allowed by OS */
245 __evEmulMask rdLast, rdNext;
246 __evEmulMask wrLast, wrNext;
247 __evEmulMask exLast, exNext;
248 __evEmulMask nonblockBefore;
249 #endif /* USE_POLL */
250 #ifdef EVENTLIB_TIME_CHECKS
251 struct timespec lastSelectTime;
256 evStream *strDone, *strLast;
258 struct timespec lastEventTime;
261 evWaitList *waitLists;
266 #define evPrintf __evPrintf
267 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
268 ISC_FORMAT_PRINTF(3, 4);
271 extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd);
272 #endif /* USE_POLL */
275 #define evCreateTimers __evCreateTimers
276 heap_context evCreateTimers(const evContext_p *);
277 #define evDestroyTimers __evDestroyTimers
278 void evDestroyTimers(const evContext_p *);
281 #define evFreeWait __evFreeWait
282 evWait *evFreeWait(evContext_p *ctx, evWait *old);
287 extern int __evOptMonoTime;
290 #endif /*_EVENTLIB_P_H*/