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.3 2005/07/28 07:43:20 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))
73 typedef struct evConn {
78 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
79 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
80 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
86 typedef struct evAccept {
90 struct sockaddr_in in;
91 #ifndef NO_SOCKADDR_UN
92 struct sockaddr_un un;
98 struct sockaddr_in in;
99 #ifndef NO_SOCKADDR_UN
100 struct sockaddr_un un;
106 LINK(struct evAccept) link;
109 typedef struct evFile {
115 struct evFile * prev;
116 struct evFile * next;
117 struct evFile * fdprev;
118 struct evFile * fdnext;
121 typedef struct evStream {
127 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */
129 struct iovec * iovOrig;
131 struct iovec * iovCur;
136 struct evStream *prevDone, *nextDone;
137 struct evStream *prev, *next;
140 typedef struct evTimer {
143 struct timespec due, inter;
146 #define EV_TMR_RATE 1
149 typedef struct evWait {
153 struct evWait * next;
156 typedef struct evWaitList {
159 struct evWaitList * prev;
160 struct evWaitList * next;
163 typedef struct evEvent_p {
164 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
166 struct { evAccept *this; } accept;
167 struct { evFile *this; int eventmask; } file;
168 struct { evStream *this; } stream;
169 struct { evTimer *this; } timer;
170 struct { evWait *this; } wait;
171 struct { struct evEvent_p *next; } free;
172 struct { const void *placeholder; } null;
178 void *ctx; /* pointer to the evContext_p */
179 uint32_t type; /* READ, WRITE, EXCEPT, nonblk */
180 uint32_t result; /* 1 => revents, 0 => events */
183 #define emulMaskInit(ctx, field, ev, lastnext) \
184 ctx->field.ctx = ctx; \
185 ctx->field.type = ev; \
186 ctx->field.result = lastnext;
188 extern short *__fd_eventfield(int fd, __evEmulMask *maskp);
189 extern short __poll_event(__evEmulMask *maskp);
190 extern void __fd_clr(int fd, __evEmulMask *maskp);
191 extern void __fd_set(int fd, __evEmulMask *maskp);
194 #define FD_ZERO(maskp)
197 #define FD_SET(fd, maskp) \
201 #define FD_CLR(fd, maskp) \
205 #define FD_ISSET(fd, maskp) \
206 ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
208 #endif /* USE_POLL */
212 const evEvent_p *cur;
218 LIST(evAccept) accepts;
220 evFile *files, *fdNext;
222 fd_set rdLast, rdNext;
223 fd_set wrLast, wrNext;
224 fd_set exLast, exNext;
225 fd_set nonblockBefore;
226 int fdMax, fdCount, highestFD;
227 evFile *fdTable[FD_SETSIZE];
229 struct pollfd *pollfds; /* Allocated as needed */
230 evFile **fdTable; /* Ditto */
231 int maxnfds; /* # elements in above */
232 int firstfd; /* First active fd */
233 int fdMax; /* Last active fd */
234 int fdCount; /* # fd:s with I/O */
235 int highestFD; /* max fd allowed by OS */
236 __evEmulMask rdLast, rdNext;
237 __evEmulMask wrLast, wrNext;
238 __evEmulMask exLast, exNext;
239 __evEmulMask nonblockBefore;
240 #endif /* USE_POLL */
241 #ifdef EVENTLIB_TIME_CHECKS
242 struct timespec lastSelectTime;
247 evStream *strDone, *strLast;
249 struct timespec lastEventTime;
252 evWaitList *waitLists;
257 #define evPrintf __evPrintf
258 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
259 ISC_FORMAT_PRINTF(3, 4);
262 extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd);
263 #endif /* USE_POLL */
266 #define evCreateTimers __evCreateTimers
267 heap_context evCreateTimers(const evContext_p *);
268 #define evDestroyTimers __evDestroyTimers
269 void evDestroyTimers(const evContext_p *);
272 #define evFreeWait __evFreeWait
273 evWait *evFreeWait(evContext_p *ctx, evWait *old);
276 extern int __evOptMonoTime;
278 #endif /*_EVENTLIB_P_H*/