|
1 /* $NetBSD: eventlib_p.h,v 1.1.1.1 2004/05/20 19:34:32 christos Exp $ */ |
|
2 |
|
3 /* |
|
4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") |
|
5 * Copyright (c) 1995-1999 by Internet Software Consortium |
|
6 * |
|
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. |
|
10 * |
|
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. |
|
18 */ |
|
19 |
|
20 /* eventlib_p.h - private interfaces for eventlib |
|
21 * vix 09sep95 [initial] |
|
22 * |
|
23 * Id: eventlib_p.h,v 1.3.2.1.4.1 2004/03/09 08:33:43 marka Exp |
|
24 */ |
|
25 |
|
26 /* |
|
27 * This version of this file is derived from Android 2.3 "Gingerbread", |
|
28 * which contains uncredited changes by Android/Google developers. It has |
|
29 * been modified in 2011 for use in the Android build of Mozilla Firefox by |
|
30 * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>, |
|
31 * and Steve Workman <sjhworkman@gmail.com>). |
|
32 * These changes are offered under the same license as the original NetBSD |
|
33 * file, whose copyright and license are unchanged above. |
|
34 */ |
|
35 |
|
36 #ifndef _EVENTLIB_P_H |
|
37 #define _EVENTLIB_P_H |
|
38 |
|
39 #include <sys/param.h> |
|
40 #include <sys/types.h> |
|
41 #include <sys/socket.h> |
|
42 #include <netinet/in.h> |
|
43 #include <sys/un.h> |
|
44 |
|
45 #define EVENTLIB_DEBUG 1 |
|
46 |
|
47 #include <errno.h> |
|
48 #include <fcntl.h> |
|
49 #include <stdio.h> |
|
50 #include <stdlib.h> |
|
51 #include <string.h> |
|
52 |
|
53 #include "heap.h" |
|
54 #include "list.h" |
|
55 #include "memcluster.h" |
|
56 |
|
57 |
|
58 #define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT) |
|
59 #define EV_ERR(e) return (errno = (e), -1) |
|
60 #define OK(x) if ((x) < 0) EV_ERR(errno); else (void)NULL |
|
61 |
|
62 |
|
63 #if HAVE_MEM_GET_SET |
|
64 #define NEW(p) if (((p) = memget(sizeof *(p))) != NULL) \ |
|
65 FILL(p); \ |
|
66 else \ |
|
67 (void)NULL; |
|
68 #define OKNEW(p) if (!((p) = memget(sizeof *(p)))) { \ |
|
69 errno = ENOMEM; \ |
|
70 return (-1); \ |
|
71 } else \ |
|
72 FILL(p) |
|
73 #define FREE(p) memput((p), sizeof *(p)) |
|
74 |
|
75 #if EVENTLIB_DEBUG |
|
76 #define FILL(p) memset((p), 0xF5, sizeof *(p)) |
|
77 #else |
|
78 #define FILL(p) |
|
79 #endif |
|
80 |
|
81 #else |
|
82 |
|
83 #define NEW(p) p = malloc(sizeof *(p)); |
|
84 #define OKNEW(p) if (!((p) = malloc(sizeof *(p)))) { errno = ENOMEM; return (-1); } |
|
85 #define FREE(p) free(p) |
|
86 #define FILL(p) |
|
87 |
|
88 #endif |
|
89 |
|
90 |
|
91 typedef struct evConn { |
|
92 evConnFunc func; |
|
93 void * uap; |
|
94 int fd; |
|
95 int flags; |
|
96 #define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */ |
|
97 #define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */ |
|
98 #define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */ |
|
99 evFileID file; |
|
100 struct evConn * prev; |
|
101 struct evConn * next; |
|
102 } evConn; |
|
103 |
|
104 typedef struct evAccept { |
|
105 int fd; |
|
106 union { |
|
107 struct sockaddr sa; |
|
108 struct sockaddr_in in; |
|
109 #ifndef NO_SOCKADDR_UN |
|
110 struct sockaddr_un un; |
|
111 #endif |
|
112 } la; |
|
113 socklen_t lalen; |
|
114 union { |
|
115 struct sockaddr sa; |
|
116 struct sockaddr_in in; |
|
117 #ifndef NO_SOCKADDR_UN |
|
118 struct sockaddr_un un; |
|
119 #endif |
|
120 } ra; |
|
121 socklen_t ralen; |
|
122 int ioErrno; |
|
123 evConn * conn; |
|
124 LINK(struct evAccept) link; |
|
125 } evAccept; |
|
126 |
|
127 typedef struct evFile { |
|
128 evFileFunc func; |
|
129 void * uap; |
|
130 int fd; |
|
131 int eventmask; |
|
132 int preemptive; |
|
133 struct evFile * prev; |
|
134 struct evFile * next; |
|
135 struct evFile * fdprev; |
|
136 struct evFile * fdnext; |
|
137 } evFile; |
|
138 |
|
139 typedef struct evStream { |
|
140 evStreamFunc func; |
|
141 void * uap; |
|
142 evFileID file; |
|
143 evTimerID timer; |
|
144 int flags; |
|
145 #define EV_STR_TIMEROK 0x0001 /* IFF timer valid. */ |
|
146 int fd; |
|
147 struct iovec * iovOrig; |
|
148 int iovOrigCount; |
|
149 struct iovec * iovCur; |
|
150 int iovCurCount; |
|
151 int ioTotal; |
|
152 int ioDone; |
|
153 int ioErrno; |
|
154 struct evStream *prevDone, *nextDone; |
|
155 struct evStream *prev, *next; |
|
156 } evStream; |
|
157 |
|
158 typedef struct evTimer { |
|
159 evTimerFunc func; |
|
160 void * uap; |
|
161 struct timespec due, inter; |
|
162 int index; |
|
163 int mode; |
|
164 #define EV_TMR_RATE 1 |
|
165 } evTimer; |
|
166 |
|
167 typedef struct evWait { |
|
168 evWaitFunc func; |
|
169 void * uap; |
|
170 const void * tag; |
|
171 struct evWait * next; |
|
172 } evWait; |
|
173 |
|
174 typedef struct evWaitList { |
|
175 evWait * first; |
|
176 evWait * last; |
|
177 struct evWaitList * prev; |
|
178 struct evWaitList * next; |
|
179 } evWaitList; |
|
180 |
|
181 typedef struct evEvent_p { |
|
182 enum { Accept, File, Stream, Timer, Wait, Free, Null } type; |
|
183 union { |
|
184 struct { evAccept *this; } accept; |
|
185 struct { evFile *this; int eventmask; } file; |
|
186 struct { evStream *this; } stream; |
|
187 struct { evTimer *this; } timer; |
|
188 struct { evWait *this; } wait; |
|
189 struct { struct evEvent_p *next; } free; |
|
190 struct { const void *placeholder; } null; |
|
191 } u; |
|
192 } evEvent_p; |
|
193 |
|
194 typedef struct { |
|
195 /* Global. */ |
|
196 const evEvent_p *cur; |
|
197 /* Debugging. */ |
|
198 int debug; |
|
199 FILE *output; |
|
200 /* Connections. */ |
|
201 evConn *conns; |
|
202 LIST(evAccept) accepts; |
|
203 /* Files. */ |
|
204 evFile *files, *fdNext; |
|
205 fd_set rdLast, rdNext; |
|
206 fd_set wrLast, wrNext; |
|
207 fd_set exLast, exNext; |
|
208 fd_set nonblockBefore; |
|
209 int fdMax, fdCount, highestFD; |
|
210 evFile *fdTable[FD_SETSIZE]; |
|
211 #ifdef EVENTLIB_TIME_CHECKS |
|
212 struct timespec lastSelectTime; |
|
213 int lastFdCount; |
|
214 #endif |
|
215 /* Streams. */ |
|
216 evStream *streams; |
|
217 evStream *strDone, *strLast; |
|
218 /* Timers. */ |
|
219 struct timespec lastEventTime; |
|
220 heap_context timers; |
|
221 /* Waits. */ |
|
222 evWaitList *waitLists; |
|
223 evWaitList waitDone; |
|
224 } evContext_p; |
|
225 |
|
226 /* eventlib.c */ |
|
227 #define evPrintf __evPrintf |
|
228 void evPrintf(const evContext_p *ctx, int level, const char *fmt, ...); |
|
229 |
|
230 /* ev_timers.c */ |
|
231 #define evCreateTimers __evCreateTimers |
|
232 heap_context evCreateTimers(const evContext_p *); |
|
233 #define evDestroyTimers __evDestroyTimers |
|
234 void evDestroyTimers(const evContext_p *); |
|
235 |
|
236 /* ev_waits.c */ |
|
237 #define evFreeWait __evFreeWait |
|
238 evWait *evFreeWait(evContext_p *ctx, evWait *old); |
|
239 |
|
240 /* Global options */ |
|
241 int __evOptMonoTime; |
|
242 |
|
243 #endif /*_EVENTLIB_P_H*/ |