Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / bind / isc / eventlib_p.h
blob1bd11bc11144669b48d5db6a1f6a3ea9218760b2
1 /*
2 * Copyright (c) 2004 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.2 2004/03/09 09:17:35 marka Exp $
24 #ifndef _EVENTLIB_P_H
25 #define _EVENTLIB_P_H
27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <sys/un.h>
33 #define EVENTLIB_DEBUG 1
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
41 #include <isc/heap.h>
42 #include <isc/list.h>
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) \
50 FILL(p); \
51 else \
52 (void)NULL;
53 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \
54 errno = ENOMEM; \
55 return (-1); \
56 } else \
57 FILL(p)
58 #define FREE(p) memput((p), sizeof *(p))
60 #if EVENTLIB_DEBUG
61 #define FILL(p) memset((p), 0xF5, sizeof *(p))
62 #else
63 #define FILL(p)
64 #endif
66 typedef struct evConn {
67 evConnFunc func;
68 void * uap;
69 int fd;
70 int flags;
71 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
72 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
73 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
74 evFileID file;
75 struct evConn * prev;
76 struct evConn * next;
77 } evConn;
79 typedef struct evAccept {
80 int fd;
81 union {
82 struct sockaddr sa;
83 struct sockaddr_in in;
84 #ifndef NO_SOCKADDR_UN
85 struct sockaddr_un un;
86 #endif
87 } la;
88 ISC_SOCKLEN_T lalen;
89 union {
90 struct sockaddr sa;
91 struct sockaddr_in in;
92 #ifndef NO_SOCKADDR_UN
93 struct sockaddr_un un;
94 #endif
95 } ra;
96 ISC_SOCKLEN_T ralen;
97 int ioErrno;
98 evConn * conn;
99 LINK(struct evAccept) link;
100 } evAccept;
102 typedef struct evFile {
103 evFileFunc func;
104 void * uap;
105 int fd;
106 int eventmask;
107 int preemptive;
108 struct evFile * prev;
109 struct evFile * next;
110 struct evFile * fdprev;
111 struct evFile * fdnext;
112 } evFile;
114 typedef struct evStream {
115 evStreamFunc func;
116 void * uap;
117 evFileID file;
118 evTimerID timer;
119 int flags;
120 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */
121 int fd;
122 struct iovec * iovOrig;
123 int iovOrigCount;
124 struct iovec * iovCur;
125 int iovCurCount;
126 int ioTotal;
127 int ioDone;
128 int ioErrno;
129 struct evStream *prevDone, *nextDone;
130 struct evStream *prev, *next;
131 } evStream;
133 typedef struct evTimer {
134 evTimerFunc func;
135 void * uap;
136 struct timespec due, inter;
137 int index;
138 int mode;
139 #define EV_TMR_RATE 1
140 } evTimer;
142 typedef struct evWait {
143 evWaitFunc func;
144 void * uap;
145 const void * tag;
146 struct evWait * next;
147 } evWait;
149 typedef struct evWaitList {
150 evWait * first;
151 evWait * last;
152 struct evWaitList * prev;
153 struct evWaitList * next;
154 } evWaitList;
156 typedef struct evEvent_p {
157 enum { Accept, File, Stream, Timer, Wait, Free, Null } type;
158 union {
159 struct { evAccept *this; } accept;
160 struct { evFile *this; int eventmask; } file;
161 struct { evStream *this; } stream;
162 struct { evTimer *this; } timer;
163 struct { evWait *this; } wait;
164 struct { struct evEvent_p *next; } free;
165 struct { const void *placeholder; } null;
166 } u;
167 } evEvent_p;
169 typedef struct {
170 /* Global. */
171 const evEvent_p *cur;
172 /* Debugging. */
173 int debug;
174 FILE *output;
175 /* Connections. */
176 evConn *conns;
177 LIST(evAccept) accepts;
178 /* Files. */
179 evFile *files, *fdNext;
180 fd_set rdLast, rdNext;
181 fd_set wrLast, wrNext;
182 fd_set exLast, exNext;
183 fd_set nonblockBefore;
184 int fdMax, fdCount, highestFD;
185 evFile *fdTable[FD_SETSIZE];
186 #ifdef EVENTLIB_TIME_CHECKS
187 struct timespec lastSelectTime;
188 int lastFdCount;
189 #endif
190 /* Streams. */
191 evStream *streams;
192 evStream *strDone, *strLast;
193 /* Timers. */
194 struct timespec lastEventTime;
195 heap_context timers;
196 /* Waits. */
197 evWaitList *waitLists;
198 evWaitList waitDone;
199 } evContext_p;
201 /* eventlib.c */
202 #define evPrintf __evPrintf
203 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...)
204 ISC_FORMAT_PRINTF(3, 4);
206 /* ev_timers.c */
207 #define evCreateTimers __evCreateTimers
208 heap_context evCreateTimers(const evContext_p *);
209 #define evDestroyTimers __evDestroyTimers
210 void evDestroyTimers(const evContext_p *);
212 /* ev_waits.c */
213 #define evFreeWait __evFreeWait
214 evWait *evFreeWait(evContext_p *ctx, evWait *old);
216 /* Global options */
217 int __evOptMonoTime;
219 #endif /*_EVENTLIB_P_H*/