1 /* $NetBSD: eventlib_p.h,v 1.1.1.4 2009/04/12 16:35:46 christos Exp $ */
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
30 #include <sys/param.h>
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <netinet/in.h>
36 #define EVENTLIB_DEBUG 1
46 #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. */
91 typedef struct evAccept
{
95 struct sockaddr_in in
;
96 #ifndef NO_SOCKADDR_UN
97 struct sockaddr_un un
;
103 struct sockaddr_in in
;
104 #ifndef NO_SOCKADDR_UN
105 struct sockaddr_un un
;
111 LINK(struct evAccept
) link
;
114 typedef struct evFile
{
120 struct evFile
* prev
;
121 struct evFile
* next
;
122 struct evFile
* fdprev
;
123 struct evFile
* fdnext
;
126 typedef struct evStream
{
132 #define EV_STR_TIMEROK 0x0001 /*%< IFF timer valid. */
134 struct iovec
* iovOrig
;
136 struct iovec
* iovCur
;
141 struct evStream
*prevDone
, *nextDone
;
142 struct evStream
*prev
, *next
;
145 typedef struct evTimer
{
148 struct timespec due
, inter
;
151 #define EV_TMR_RATE 1
154 typedef struct evWait
{
158 struct evWait
* next
;
161 typedef struct evWaitList
{
164 struct evWaitList
* prev
;
165 struct evWaitList
* next
;
168 typedef struct evEvent_p
{
169 enum { Accept
, File
, Stream
, Timer
, Wait
, Free
, Null
} type
;
171 struct { evAccept
*this; } accept
;
172 struct { evFile
*this; int eventmask
; } file
;
173 struct { evStream
*this; } stream
;
174 struct { evTimer
*this; } timer
;
175 struct { evWait
*this; } wait
;
176 struct { struct evEvent_p
*next
; } free
;
177 struct { const void *placeholder
; } null
;
183 void *ctx
; /* pointer to the evContext_p */
184 uint32_t type
; /* READ, WRITE, EXCEPT, nonblk */
185 uint32_t result
; /* 1 => revents, 0 => events */
188 #define emulMaskInit(ctx, field, ev, lastnext) \
189 ctx->field.ctx = ctx; \
190 ctx->field.type = ev; \
191 ctx->field.result = lastnext;
193 extern short *__fd_eventfield(int fd
, __evEmulMask
*maskp
);
194 extern short __poll_event(__evEmulMask
*maskp
);
195 extern void __fd_clr(int fd
, __evEmulMask
*maskp
);
196 extern void __fd_set(int fd
, __evEmulMask
*maskp
);
199 #define FD_ZERO(maskp)
202 #define FD_SET(fd, maskp) \
206 #define FD_CLR(fd, maskp) \
210 #define FD_ISSET(fd, maskp) \
211 ((*__fd_eventfield(fd, maskp) & __poll_event(maskp)) != 0)
213 #endif /* USE_POLL */
217 const evEvent_p
*cur
;
223 LIST(evAccept
) accepts
;
225 evFile
*files
, *fdNext
;
227 fd_set rdLast
, rdNext
;
228 fd_set wrLast
, wrNext
;
229 fd_set exLast
, exNext
;
230 fd_set nonblockBefore
;
231 int fdMax
, fdCount
, highestFD
;
232 evFile
*fdTable
[FD_SETSIZE
];
234 struct pollfd
*pollfds
; /* Allocated as needed */
235 evFile
**fdTable
; /* Ditto */
236 int maxnfds
; /* # elements in above */
237 int firstfd
; /* First active fd */
238 int fdMax
; /* Last active fd */
239 int fdCount
; /* # fd:s with I/O */
240 int highestFD
; /* max fd allowed by OS */
241 __evEmulMask rdLast
, rdNext
;
242 __evEmulMask wrLast
, wrNext
;
243 __evEmulMask exLast
, exNext
;
244 __evEmulMask nonblockBefore
;
245 #endif /* USE_POLL */
246 #ifdef EVENTLIB_TIME_CHECKS
247 struct timespec lastSelectTime
;
252 evStream
*strDone
, *strLast
;
254 struct timespec lastEventTime
;
257 evWaitList
*waitLists
;
262 #define evPrintf __evPrintf
263 void evPrintf(const evContext_p
*ctx
, int level
, const char *fmt
, ...)
264 ISC_FORMAT_PRINTF(3, 4);
267 extern int evPollfdRealloc(evContext_p
*ctx
, int pollfd_chunk_size
, int fd
);
268 #endif /* USE_POLL */
271 #define evCreateTimers __evCreateTimers
272 heap_context
evCreateTimers(const evContext_p
*);
273 #define evDestroyTimers __evDestroyTimers
274 void evDestroyTimers(const evContext_p
*);
277 #define evFreeWait __evFreeWait
278 evWait
*evFreeWait(evContext_p
*ctx
, evWait
*old
);
281 extern int __evOptMonoTime
;
283 #endif /*_EVENTLIB_P_H*/