2 * SPDX-License-Identifier: ISC
4 * Copyright (c) 2005 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1995-1999 by Internet Software Consortium
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.
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.
21 * \brief private interfaces for eventlib
22 * \author vix 09sep95 [initial]
24 * $Id: eventlib_p.h,v 1.9 2006/03/09 23:57:56 marka Exp $
31 #include <sys/param.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
36 #define EVENTLIB_DEBUG 1
47 #include <isc/memcluster.h>
50 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
51 #define EV_ERR(e) return (errno = (e), -1)
52 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
53 #define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \
56 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
60 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
65 #define FREE(p) memput((p), sizeof *(p))
68 #define FILL(p) memset((p), 0xF5, sizeof *(p))
80 typedef struct evConn {
85 #define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */
86 #define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */
87 #define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */
94 typedef struct evAccept {
98 struct sockaddr_in in;
99 #ifndef NO_SOCKADDR_UN
100 struct sockaddr_un un;
106 struct sockaddr_in in;
107 #ifndef NO_SOCKADDR_UN
108 struct sockaddr_un un;
114 LINK(struct evAccept) link;
117 typedef struct evFile {
123 struct evFile * prev;
124 struct evFile * next;
125 struct evFile * fdprev;
126 struct evFile * fdnext;
129 typedef struct evStream {
135 #define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */
137 struct iovec * iovOrig;
139 struct iovec * iovCur;
144 struct evStream *prevDone, *nextDone;
145 struct evStream *prev, *next;
148 typedef struct evTimer {
151 struct timespec due, inter;
154 #define EV_TMR_RATE 1
157 typedef struct evWait {
161 struct evWait * next;
164 typedef struct evWaitList {
167 struct evWaitList * prev;
168 struct evWaitList * next;
171 typedef struct evEvent_p {
172 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
174 struct { evAccept *this; } accept;
175 struct { evFile *this; int eventmask; } file;
176 struct { evStream *this; } stream;
177 struct { evTimer *this; } timer;
178 struct { evWait *this; } wait;
179 struct { struct evEvent_p *next; } free;
180 struct { const void *placeholder; } null;
187 void *ctx; /* pointer to the evContext_p */
188 uint32_t type; /* READ, WRITE, EXCEPT, nonblk */
189 uint32_t result; /* 1 => revents, 0 => events */
192 #define emulMaskInit(ctx, field, ev, lastnext) \
193 ctx->field.ctx = ctx; \
194 ctx->field.type = ev; \
195 ctx->field.result = lastnext;
197 extern short *__fd_eventfield(int fd, __evEmulMask *maskp);
198 extern short __poll_event(__evEmulMask *maskp);
199 extern void __fd_clr(int fd, __evEmulMask *maskp);
200 extern void __fd_set(int fd, __evEmulMask *maskp);
203 #define FD_ZERO(maskp)
206 #define FD_SET(fd, maskp) \
210 #define FD_CLR(fd, maskp) \
214 #define FD_ISSET(fd, maskp) \
215 ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
217 #endif /* USE_POLL */
222 const evEvent_p *cur;
228 LIST(evAccept) accepts;
230 evFile *files, *fdNext;
232 fd_set rdLast, rdNext;
233 fd_set wrLast, wrNext;
234 fd_set exLast, exNext;
235 fd_set nonblockBefore;
236 int fdMax, fdCount, highestFD;
237 evFile *fdTable[FD_SETSIZE];
239 struct pollfd *pollfds; /* Allocated as needed */
240 evFile **fdTable; /* Ditto */
241 int maxnfds; /* # elements in above */
242 int firstfd; /* First active fd */
243 int fdMax; /* Last active fd */
244 int fdCount; /* # fd:s with I/O */
245 int highestFD; /* max fd allowed by OS */
246 __evEmulMask rdLast, rdNext;
247 __evEmulMask wrLast, wrNext;
248 __evEmulMask exLast, exNext;
249 __evEmulMask nonblockBefore;
250 #endif /* USE_POLL */
251 #ifdef EVENTLIB_TIME_CHECKS
252 struct timespec lastSelectTime;
257 evStream *strDone, *strLast;
259 struct timespec lastEventTime;
262 evWaitList *waitLists;
267 #define evPrintf __evPrintf
268 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
269 ISC_FORMAT_PRINTF(3, 4);
272 extern int evPollfdRealloc(evContext_p *ctx, int pollfd_chunk_size, int fd);
273 #endif /* USE_POLL */
276 #define evCreateTimers __evCreateTimers
277 heap_context evCreateTimers(const evContext_p *);
278 #define evDestroyTimers __evDestroyTimers
279 void evDestroyTimers(const evContext_p *);
282 #define evFreeWait __evFreeWait
283 evWait *evFreeWait(evContext_p *ctx, evWait *old);
288 extern int __evOptMonoTime;
291 #endif /*_EVENTLIB_P_H*/