… | |
… | |
46 | |
46 | |
47 | #ifndef EV_MULTIPLICITY |
47 | #ifndef EV_MULTIPLICITY |
48 | # define EV_MULTIPLICITY 1 |
48 | # define EV_MULTIPLICITY 1 |
49 | #endif |
49 | #endif |
50 | |
50 | |
|
|
51 | #ifndef EV_PERIODICS |
|
|
52 | # define EV_PERIODICS 1 |
|
|
53 | #endif |
|
|
54 | |
51 | /* support multiple event loops? */ |
55 | /* support multiple event loops? */ |
52 | #if EV_MULTIPLICITY |
56 | #if EV_MULTIPLICITY |
53 | struct ev_loop; |
57 | struct ev_loop; |
54 | # define EV_P struct ev_loop *loop |
58 | # define EV_P struct ev_loop *loop |
55 | # define EV_P_ EV_P, |
59 | # define EV_P_ EV_P, |
… | |
… | |
67 | #endif |
71 | #endif |
68 | |
72 | |
69 | /* eventmask, revents, events... */ |
73 | /* eventmask, revents, events... */ |
70 | #define EV_UNDEF -1 /* guaranteed to be invalid */ |
74 | #define EV_UNDEF -1 /* guaranteed to be invalid */ |
71 | #define EV_NONE 0x00 |
75 | #define EV_NONE 0x00 |
72 | #define EV_READ 0x01 |
76 | #define EV_READ 0x01 /* io only */ |
73 | #define EV_WRITE 0x02 |
77 | #define EV_WRITE 0x02 /* io only */ |
74 | #define EV_TIMEOUT 0x000100 |
78 | #define EV_TIMEOUT 0x000100 /* timer only */ |
75 | #define EV_PERIODIC 0x000200 |
79 | #define EV_PERIODIC 0x000200 /* periodic timer only */ |
76 | #define EV_SIGNAL 0x000400 |
80 | #define EV_SIGNAL 0x000400 /* signal only */ |
77 | #define EV_IDLE 0x000800 |
81 | #define EV_IDLE 0x000800 /* idle only */ |
78 | #define EV_CHECK 0x001000 |
82 | #define EV_CHECK 0x001000 /* check only */ |
79 | #define EV_PREPARE 0x002000 |
83 | #define EV_PREPARE 0x002000 /* prepare only */ |
80 | #define EV_CHILD 0x004000 |
84 | #define EV_CHILD 0x004000 /* child/pid only */ |
81 | #define EV_ERROR 0x800000 /* sent when an error occurs */ |
85 | #define EV_ERROR 0x800000 /* sent when an error occurs */ |
82 | |
86 | |
83 | /* can be used to add custom fields to all watchers */ |
87 | /* can be used to add custom fields to all watchers, while losing binary compatibility */ |
84 | #ifndef EV_COMMON |
88 | #ifndef EV_COMMON |
85 | # define EV_COMMON void *data |
89 | # define EV_COMMON void *data; |
86 | #endif |
90 | #endif |
87 | #ifndef EV_PROTOTYPES |
91 | #ifndef EV_PROTOTYPES |
88 | # define EV_PROTOTYPES 1 |
92 | # define EV_PROTOTYPES 1 |
89 | #endif |
93 | #endif |
90 | |
94 | |
… | |
… | |
108 | /* shared by all watchers */ |
112 | /* shared by all watchers */ |
109 | #define EV_WATCHER(type) \ |
113 | #define EV_WATCHER(type) \ |
110 | int active; /* private */ \ |
114 | int active; /* private */ \ |
111 | int pending; /* private */ \ |
115 | int pending; /* private */ \ |
112 | int priority; /* private */ \ |
116 | int priority; /* private */ \ |
113 | EV_COMMON; /* rw */ \ |
117 | EV_COMMON /* rw */ \ |
114 | EV_CB_DECLARE (type) /* private */ |
118 | EV_CB_DECLARE (type) /* private */ |
115 | |
119 | |
116 | #define EV_WATCHER_LIST(type) \ |
120 | #define EV_WATCHER_LIST(type) \ |
117 | EV_WATCHER (type); \ |
121 | EV_WATCHER (type) \ |
118 | struct ev_watcher_list *next /* private */ |
122 | struct ev_watcher_list *next; /* private */ |
119 | |
123 | |
120 | #define EV_WATCHER_TIME(type) \ |
124 | #define EV_WATCHER_TIME(type) \ |
121 | EV_WATCHER (type); \ |
125 | EV_WATCHER (type) \ |
122 | ev_tstamp at /* private */ |
126 | ev_tstamp at; /* private */ |
123 | |
127 | |
124 | /* base class, nothing to see here unless you subclass */ |
128 | /* base class, nothing to see here unless you subclass */ |
125 | struct ev_watcher |
129 | struct ev_watcher |
126 | { |
130 | { |
127 | EV_WATCHER (ev_watcher); |
131 | EV_WATCHER (ev_watcher) |
128 | }; |
132 | }; |
129 | |
133 | |
130 | /* base class, nothing to see here unless you subclass */ |
134 | /* base class, nothing to see here unless you subclass */ |
131 | struct ev_watcher_list |
135 | struct ev_watcher_list |
132 | { |
136 | { |
133 | EV_WATCHER_LIST (ev_watcher_list); |
137 | EV_WATCHER_LIST (ev_watcher_list) |
134 | }; |
138 | }; |
135 | |
139 | |
136 | /* base class, nothing to see here unless you subclass */ |
140 | /* base class, nothing to see here unless you subclass */ |
137 | struct ev_watcher_time |
141 | struct ev_watcher_time |
138 | { |
142 | { |
139 | EV_WATCHER_TIME (ev_watcher_time); |
143 | EV_WATCHER_TIME (ev_watcher_time) |
140 | }; |
144 | }; |
141 | |
145 | |
142 | /* invoked after a specific time, repeatable (based on monotonic clock) */ |
146 | /* invoked after a specific time, repeatable (based on monotonic clock) */ |
143 | /* revent EV_TIMEOUT */ |
147 | /* revent EV_TIMEOUT */ |
144 | struct ev_timer |
148 | struct ev_timer |
145 | { |
149 | { |
146 | EV_WATCHER_TIME (ev_timer); |
150 | EV_WATCHER_TIME (ev_timer) |
147 | |
151 | |
148 | ev_tstamp repeat; /* rw */ |
152 | ev_tstamp repeat; /* rw */ |
149 | }; |
153 | }; |
150 | |
154 | |
151 | /* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */ |
155 | /* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */ |
152 | /* revent EV_PERIODIC */ |
156 | /* revent EV_PERIODIC */ |
153 | struct ev_periodic |
157 | struct ev_periodic |
154 | { |
158 | { |
155 | EV_WATCHER_TIME (ev_periodic); |
159 | EV_WATCHER_TIME (ev_periodic) |
156 | |
160 | |
157 | ev_tstamp interval; /* rw */ |
161 | ev_tstamp interval; /* rw */ |
158 | ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ |
162 | ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ |
159 | }; |
163 | }; |
160 | |
164 | |
161 | /* invoked when fd is either EV_READable or EV_WRITEable */ |
165 | /* invoked when fd is either EV_READable or EV_WRITEable */ |
162 | /* revent EV_READ, EV_WRITE */ |
166 | /* revent EV_READ, EV_WRITE */ |
163 | struct ev_io |
167 | struct ev_io |
164 | { |
168 | { |
165 | EV_WATCHER_LIST (ev_io); |
169 | EV_WATCHER_LIST (ev_io) |
166 | |
170 | |
167 | int fd; /* ro */ |
171 | int fd; /* ro */ |
168 | int events; /* ro */ |
172 | int events; /* ro */ |
169 | }; |
173 | }; |
170 | |
174 | |
171 | /* invoked when the given signal has been received */ |
175 | /* invoked when the given signal has been received */ |
172 | /* revent EV_SIGNAL */ |
176 | /* revent EV_SIGNAL */ |
173 | struct ev_signal |
177 | struct ev_signal |
174 | { |
178 | { |
175 | EV_WATCHER_LIST (ev_signal); |
179 | EV_WATCHER_LIST (ev_signal) |
176 | |
180 | |
177 | int signum; /* ro */ |
181 | int signum; /* ro */ |
178 | }; |
182 | }; |
179 | |
183 | |
180 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
184 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
181 | /* revent EV_IDLE */ |
185 | /* revent EV_IDLE */ |
182 | struct ev_idle |
186 | struct ev_idle |
183 | { |
187 | { |
184 | EV_WATCHER (ev_idle); |
188 | EV_WATCHER (ev_idle) |
185 | }; |
189 | }; |
186 | |
190 | |
187 | /* invoked for each run of the mainloop, just before the blocking call */ |
191 | /* invoked for each run of the mainloop, just before the blocking call */ |
188 | /* you can still change events in any way you like */ |
192 | /* you can still change events in any way you like */ |
189 | /* revent EV_PREPARE */ |
193 | /* revent EV_PREPARE */ |
190 | struct ev_prepare |
194 | struct ev_prepare |
191 | { |
195 | { |
192 | EV_WATCHER (ev_prepare); |
196 | EV_WATCHER (ev_prepare) |
193 | }; |
197 | }; |
194 | |
198 | |
195 | /* invoked for each run of the mainloop, just after the blocking call */ |
199 | /* invoked for each run of the mainloop, just after the blocking call */ |
196 | /* revent EV_CHECK */ |
200 | /* revent EV_CHECK */ |
197 | struct ev_check |
201 | struct ev_check |
198 | { |
202 | { |
199 | EV_WATCHER (ev_check); |
203 | EV_WATCHER (ev_check) |
200 | }; |
204 | }; |
201 | |
205 | |
202 | /* invoked when sigchld is received and waitpid indicates the givne pid */ |
206 | /* invoked when sigchld is received and waitpid indicates the given pid */ |
203 | /* revent EV_CHILD */ |
207 | /* revent EV_CHILD */ |
204 | /* does not support priorities */ |
208 | /* does not support priorities */ |
205 | struct ev_child |
209 | struct ev_child |
206 | { |
210 | { |
207 | EV_WATCHER_LIST (ev_child); |
211 | EV_WATCHER_LIST (ev_child) |
208 | |
212 | |
209 | int pid; /* ro */ |
213 | int pid; /* ro */ |
210 | int rpid; /* rw, holds the received pid */ |
214 | int rpid; /* rw, holds the received pid */ |
211 | int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ |
215 | int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ |
212 | }; |
216 | }; |
… | |
… | |
225 | struct ev_check check; |
229 | struct ev_check check; |
226 | struct ev_signal signal; |
230 | struct ev_signal signal; |
227 | struct ev_child child; |
231 | struct ev_child child; |
228 | }; |
232 | }; |
229 | |
233 | |
230 | #define EVMETHOD_AUTO 0 /* consults environment */ |
234 | /* bits for ev_default_loop and ev_loop_new */ |
231 | #define EVMETHOD_SELECT 1 |
235 | /* the default */ |
232 | #define EVMETHOD_POLL 2 |
236 | #define EVFLAG_AUTO 0x00000000 /* not quite a mask */ |
233 | #define EVMETHOD_EPOLL 4 |
237 | |
234 | #define EVMETHOD_KQUEUE 8 |
238 | /* method bits to be ored together */ |
235 | #define EVMETHOD_DEVPOLL 16 /* NYI */ |
239 | #define EVMETHOD_SELECT 0x00000001 /* about anywhere */ |
236 | #define EVMETHOD_PORT 32 /* NYI */ |
240 | #define EVMETHOD_POLL 0x00000002 /* !win */ |
237 | #define EVMETHOD_WIN32 64 /* NYI */ |
241 | #define EVMETHOD_EPOLL 0x00000004 /* linux */ |
238 | #define EVMETHOD_ANY ~0 /* any method, do not consult env */ |
242 | #define EVMETHOD_KQUEUE 0x00000008 /* bsd */ |
|
|
243 | #define EVMETHOD_DEVPOLL 0x00000010 /* solaris 8 */ /* NYI */ |
|
|
244 | #define EVMETHOD_PORT 0x00000020 /* solaris 10 */ /* NYI */ |
|
|
245 | |
|
|
246 | /* flag bits */ |
|
|
247 | #define EVFLAG_NOENV 0x01000000 /* do NOT consult environment */ |
239 | |
248 | |
240 | #if EV_PROTOTYPES |
249 | #if EV_PROTOTYPES |
241 | int ev_version_major (void); |
250 | int ev_version_major (void); |
242 | int ev_version_minor (void); |
251 | int ev_version_minor (void); |
243 | |
252 | |
… | |
… | |
258 | void ev_set_syserr_cb (void (*cb)(const char *msg)); |
267 | void ev_set_syserr_cb (void (*cb)(const char *msg)); |
259 | |
268 | |
260 | # if EV_MULTIPLICITY |
269 | # if EV_MULTIPLICITY |
261 | /* the default loop is the only one that handles signals and child watchers */ |
270 | /* the default loop is the only one that handles signals and child watchers */ |
262 | /* you can call this as often as you like */ |
271 | /* you can call this as often as you like */ |
263 | struct ev_loop *ev_default_loop (int methods); /* returns default loop */ |
272 | struct ev_loop *ev_default_loop (unsigned int flags); /* returns default loop */ |
264 | |
273 | |
265 | /* create and destroy alternative loops that don't handle signals */ |
274 | /* create and destroy alternative loops that don't handle signals */ |
266 | struct ev_loop *ev_loop_new (int methods); |
275 | struct ev_loop *ev_loop_new (unsigned int flags); |
267 | void ev_loop_destroy (EV_P); |
276 | void ev_loop_destroy (EV_P); |
268 | void ev_loop_fork (EV_P); |
277 | void ev_loop_fork (EV_P); |
269 | |
278 | |
270 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
279 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
271 | |
280 | |
272 | # else |
281 | # else |
273 | |
282 | |
274 | int ev_default_loop (int methods); /* returns true when successful */ |
283 | int ev_default_loop (unsigned int flags); /* returns true when successful */ |
275 | |
284 | |
276 | static ev_tstamp |
285 | static ev_tstamp |
277 | ev_now () |
286 | ev_now (void) |
278 | { |
287 | { |
279 | extern ev_tstamp ev_rt_now; |
288 | extern ev_tstamp ev_rt_now; |
280 | |
289 | |
281 | return ev_rt_now; |
290 | return ev_rt_now; |
282 | } |
291 | } |
… | |
… | |
287 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
296 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
288 | /* you can call it in either the parent or the child */ |
297 | /* you can call it in either the parent or the child */ |
289 | /* you can actually call it at any time, anywhere :) */ |
298 | /* you can actually call it at any time, anywhere :) */ |
290 | void ev_default_fork (void); |
299 | void ev_default_fork (void); |
291 | |
300 | |
292 | int ev_method (EV_P); |
301 | unsigned int ev_method (EV_P); |
293 | #endif |
302 | #endif |
294 | |
303 | |
295 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
304 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
296 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
305 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
297 | #define EVUNLOOP_ONCE 1 /* unloop once */ |
306 | #define EVUNLOOP_ONCE 1 /* unloop once */ |
… | |
… | |
368 | void ev_timer_start (EV_P_ struct ev_timer *w); |
377 | void ev_timer_start (EV_P_ struct ev_timer *w); |
369 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
378 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
370 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
379 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
371 | void ev_timer_again (EV_P_ struct ev_timer *w); |
380 | void ev_timer_again (EV_P_ struct ev_timer *w); |
372 | |
381 | |
|
|
382 | #if EV_PERIODICS |
373 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
383 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
374 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
384 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
375 | void ev_periodic_again (EV_P_ struct ev_periodic *w); |
385 | void ev_periodic_again (EV_P_ struct ev_periodic *w); |
|
|
386 | #endif |
376 | |
387 | |
377 | void ev_idle_start (EV_P_ struct ev_idle *w); |
388 | void ev_idle_start (EV_P_ struct ev_idle *w); |
378 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
389 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
379 | |
390 | |
380 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |
391 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |