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.9 2006/03/09 23:57:56 marka Exp $
28 #include <sys/param.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
34 #define EVENTLIB_DEBUG 1
45 #include <isc/memcluster.h>
48 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
49 #define EV_ERR(e) return (errno = (e), -1)
50 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL
51 #define OKFREE(x, y) if ((x) < 0) { FREE((y)); EV_ERR(errno); } \
54 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \
58 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
63 #define FREE(p) memput((p), sizeof *(p))
66 #define FILL(p) memset((p), 0xF5, sizeof *(p))
78 typedef struct evConn
{
83 #define EV_CONN_LISTEN 0x0001 /*%< Connection is a listener. */
84 #define EV_CONN_SELECTED 0x0002 /*%< evSelectFD(conn->file). */
85 #define EV_CONN_BLOCK 0x0004 /*%< Listener fd was blocking. */
92 typedef struct evAccept
{
96 struct sockaddr_in in
;
97 #ifndef NO_SOCKADDR_UN
98 struct sockaddr_un un
;
104 struct sockaddr_in in
;
105 #ifndef NO_SOCKADDR_UN
106 struct sockaddr_un un
;
112 LINK(struct evAccept
) link
;
115 typedef struct evFile
{
121 struct evFile
* prev
;
122 struct evFile
* next
;
123 struct evFile
* fdprev
;
124 struct evFile
* fdnext
;
127 typedef struct evStream
{
133 #define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */
135 struct iovec
* iovOrig
;
137 struct iovec
* iovCur
;
142 struct evStream
*prevDone
, *nextDone
;
143 struct evStream
*prev
, *next
;
146 typedef struct evTimer
{
149 struct timespec due
, inter
;
152 #define EV_TMR_RATE 1
155 typedef struct evWait
{
159 struct evWait
* next
;
162 typedef struct evWaitList
{
165 struct evWaitList
* prev
;
166 struct evWaitList
* next
;
169 typedef struct evEvent_p
{
170 enum { Accept
, File
, Stream
, Timer
, Wait
, Free
, Null
} type
;
172 struct { evAccept
*this; } accept
;
173 struct { evFile
*this; int eventmask
; } file
;
174 struct { evStream
*this; } stream
;
175 struct { evTimer
*this; } timer
;
176 struct { evWait
*this; } wait
;
177 struct { struct evEvent_p
*next
; } free
;
178 struct { const void *placeholder
; } null
;
185 void *ctx
; /* pointer to the evContext_p */
186 uint32_t type
; /* READ, WRITE, EXCEPT, nonblk */
187 uint32_t result
; /* 1 => revents, 0 => events */
190 #define emulMaskInit(ctx, field, ev, lastnext) \
191 ctx->field.ctx = ctx; \
192 ctx->field.type = ev; \
193 ctx->field.result = lastnext;
195 extern short *__fd_eventfield(int fd
, __evEmulMask
*maskp
);
196 extern short __poll_event(__evEmulMask
*maskp
);
197 extern void __fd_clr(int fd
, __evEmulMask
*maskp
);
198 extern void __fd_set(int fd
, __evEmulMask
*maskp
);
201 #define FD_ZERO(maskp)
204 #define FD_SET(fd, maskp) \
208 #define FD_CLR(fd, maskp) \
212 #define FD_ISSET(fd, maskp) \
213 ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
215 #endif /* USE_POLL */
220 const evEvent_p
*cur
;
226 LIST(evAccept
) accepts
;
228 evFile
*files
, *fdNext
;
230 fd_set rdLast
, rdNext
;
231 fd_set wrLast
, wrNext
;
232 fd_set exLast
, exNext
;
233 fd_set nonblockBefore
;
234 int fdMax
, fdCount
, highestFD
;
235 evFile
*fdTable
[FD_SETSIZE
];
237 struct pollfd
*pollfds
; /* Allocated as needed */
238 evFile
**fdTable
; /* Ditto */
239 int maxnfds
; /* # elements in above */
240 int firstfd
; /* First active fd */
241 int fdMax
; /* Last active fd */
242 int fdCount
; /* # fd:s with I/O */
243 int highestFD
; /* max fd allowed by OS */
244 __evEmulMask rdLast
, rdNext
;
245 __evEmulMask wrLast
, wrNext
;
246 __evEmulMask exLast
, exNext
;
247 __evEmulMask nonblockBefore
;
248 #endif /* USE_POLL */
249 #ifdef EVENTLIB_TIME_CHECKS
250 struct timespec lastSelectTime
;
255 evStream
*strDone
, *strLast
;
257 struct timespec lastEventTime
;
260 evWaitList
*waitLists
;
265 #define evPrintf __evPrintf
266 void evPrintf(const evContext_p
*ctx
, int level
, const char *fmt
, ...)
267 ISC_FORMAT_PRINTF(3, 4);
270 extern int evPollfdRealloc(evContext_p
*ctx
, int pollfd_chunk_size
, int fd
);
271 #endif /* USE_POLL */
274 #define evCreateTimers __evCreateTimers
275 heap_context
evCreateTimers(const evContext_p
*);
276 #define evDestroyTimers __evDestroyTimers
277 void evDestroyTimers(const evContext_p
*);
280 #define evFreeWait __evFreeWait
281 evWait
*evFreeWait(evContext_p
*ctx
, evWait
*old
);
286 extern int __evOptMonoTime
;
289 #endif /*_EVENTLIB_P_H*/