1 /* $NetBSD: eventlib_p.h,v 1.1.1.1 2004/05/20 19:34:32 christos Exp $ */
4 * Copyright (c) 2004 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.
20 /* eventlib_p.h - private interfaces for eventlib
21 * vix 09sep95 [initial]
23 * Id: eventlib_p.h,v 1.3.2.1.4.1 2004/03/09 08:33:43 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
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
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))
73 #define NEW(p) p = malloc(sizeof *(p));
74 #define OKNEW(p) if (!((p) = malloc(sizeof *(p)))) { errno = ENOMEM; return (-1); }
75 #define FREE(p) free(p)
81 typedef struct evConn {
86 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
87 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
88 #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;
186 const evEvent_p *cur;
192 LIST(evAccept) accepts;
194 evFile *files, *fdNext;
195 fd_set rdLast, rdNext;
196 fd_set wrLast, wrNext;
197 fd_set exLast, exNext;
198 fd_set nonblockBefore;
199 int fdMax, fdCount, highestFD;
200 evFile *fdTable[FD_SETSIZE];
201 #ifdef EVENTLIB_TIME_CHECKS
202 struct timespec lastSelectTime;
207 evStream *strDone, *strLast;
209 struct timespec lastEventTime;
212 evWaitList *waitLists;
217 #define evPrintf __evPrintf
218 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...);
221 #define evCreateTimers __evCreateTimers
222 heap_context evCreateTimers(const evContext_p *);
223 #define evDestroyTimers __evDestroyTimers
224 void evDestroyTimers(const evContext_p *);
227 #define evFreeWait __evFreeWait
228 evWait *evFreeWait(evContext_p *ctx, evWait *old);
233 #endif /*_EVENTLIB_P_H*/