ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.h
(Generate patch)

Comparing libev/ev.h (file contents):
Revision 1.64 by root, Fri Nov 23 19:13:33 2007 UTC vs.
Revision 1.67 by root, Sat Nov 24 07:14:49 2007 UTC

125#define EV_WATCHER_TIME(type) \ 125#define EV_WATCHER_TIME(type) \
126 EV_WATCHER (type) \ 126 EV_WATCHER (type) \
127 ev_tstamp at; /* private */ 127 ev_tstamp at; /* private */
128 128
129/* base class, nothing to see here unless you subclass */ 129/* base class, nothing to see here unless you subclass */
130struct ev_watcher 130typedef struct ev_watcher
131{ 131{
132 EV_WATCHER (ev_watcher) 132 EV_WATCHER (ev_watcher)
133}; 133} ev_watcher;
134 134
135/* base class, nothing to see here unless you subclass */ 135/* base class, nothing to see here unless you subclass */
136struct ev_watcher_list 136typedef struct ev_watcher_list
137{ 137{
138 EV_WATCHER_LIST (ev_watcher_list) 138 EV_WATCHER_LIST (ev_watcher_list)
139}; 139} ev_watcher_list;
140 140
141/* base class, nothing to see here unless you subclass */ 141/* base class, nothing to see here unless you subclass */
142struct ev_watcher_time 142typedef struct ev_watcher_time
143{ 143{
144 EV_WATCHER_TIME (ev_watcher_time) 144 EV_WATCHER_TIME (ev_watcher_time)
145}; 145} ev_watcher_time;
146 146
147/* invoked after a specific time, repeatable (based on monotonic clock) */ 147/* invoked after a specific time, repeatable (based on monotonic clock) */
148/* revent EV_TIMEOUT */ 148/* revent EV_TIMEOUT */
149struct ev_timer 149typedef struct ev_timer
150{ 150{
151 EV_WATCHER_TIME (ev_timer) 151 EV_WATCHER_TIME (ev_timer)
152 152
153 ev_tstamp repeat; /* rw */ 153 ev_tstamp repeat; /* rw */
154}; 154} ev_timer;
155 155
156/* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */ 156/* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */
157/* revent EV_PERIODIC */ 157/* revent EV_PERIODIC */
158struct ev_periodic 158typedef struct ev_periodic
159{ 159{
160 EV_WATCHER_TIME (ev_periodic) 160 EV_WATCHER_TIME (ev_periodic)
161 161
162 ev_tstamp interval; /* rw */ 162 ev_tstamp interval; /* rw */
163 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ 163 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */
164}; 164} ev_periodic;
165 165
166/* invoked when fd is either EV_READable or EV_WRITEable */ 166/* invoked when fd is either EV_READable or EV_WRITEable */
167/* revent EV_READ, EV_WRITE */ 167/* revent EV_READ, EV_WRITE */
168struct ev_io 168typedef struct ev_io
169{ 169{
170 EV_WATCHER_LIST (ev_io) 170 EV_WATCHER_LIST (ev_io)
171 171
172 int fd; /* ro */ 172 int fd; /* ro */
173 int events; /* ro */ 173 int events; /* ro */
174}; 174} ev_io;
175 175
176/* invoked when the given signal has been received */ 176/* invoked when the given signal has been received */
177/* revent EV_SIGNAL */ 177/* revent EV_SIGNAL */
178struct ev_signal 178typedef struct ev_signal
179{ 179{
180 EV_WATCHER_LIST (ev_signal) 180 EV_WATCHER_LIST (ev_signal)
181 181
182 int signum; /* ro */ 182 int signum; /* ro */
183}; 183} ev_signal;
184 184
185/* invoked when the nothing else needs to be done, keeps the process from blocking */ 185/* invoked when the nothing else needs to be done, keeps the process from blocking */
186/* revent EV_IDLE */ 186/* revent EV_IDLE */
187struct ev_idle 187typedef struct ev_idle
188{ 188{
189 EV_WATCHER (ev_idle) 189 EV_WATCHER (ev_idle)
190}; 190} ev_idle;
191 191
192/* invoked for each run of the mainloop, just before the blocking call */ 192/* invoked for each run of the mainloop, just before the blocking call */
193/* you can still change events in any way you like */ 193/* you can still change events in any way you like */
194/* revent EV_PREPARE */ 194/* revent EV_PREPARE */
195struct ev_prepare 195typedef struct ev_prepare
196{ 196{
197 EV_WATCHER (ev_prepare) 197 EV_WATCHER (ev_prepare)
198}; 198} ev_prepare;
199 199
200/* invoked for each run of the mainloop, just after the blocking call */ 200/* invoked for each run of the mainloop, just after the blocking call */
201/* revent EV_CHECK */ 201/* revent EV_CHECK */
202struct ev_check 202typedef struct ev_check
203{ 203{
204 EV_WATCHER (ev_check) 204 EV_WATCHER (ev_check)
205}; 205} ev_check;
206 206
207/* invoked when sigchld is received and waitpid indicates the given pid */ 207/* invoked when sigchld is received and waitpid indicates the given pid */
208/* revent EV_CHILD */ 208/* revent EV_CHILD */
209/* does not support priorities */ 209/* does not support priorities */
210struct ev_child 210typedef struct ev_child
211{ 211{
212 EV_WATCHER_LIST (ev_child) 212 EV_WATCHER_LIST (ev_child)
213 213
214 int pid; /* ro */ 214 int pid; /* ro */
215 int rpid; /* rw, holds the received pid */ 215 int rpid; /* rw, holds the received pid */
216 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ 216 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */
217}; 217} ev_child;
218 218
219#if EV_MULTIPLICITY 219#if EV_MULTIPLICITY
220/* used to embed an event loop inside another */ 220/* used to embed an event loop inside another */
221/* the callback gets invoked when the event loop has handled events, and can be 0 */ 221/* the callback gets invoked when the event loop has handled events, and can be 0 */
222struct ev_embed 222typedef struct ev_embed
223{ 223{
224 EV_WATCHER (ev_embed) 224 EV_WATCHER (ev_embed)
225 225
226 struct ev_io io; /* private */ 226 ev_io io; /* private */
227 struct ev_loop *loop; /* ro */ 227 struct ev_loop *loop; /* ro */
228}; 228} ev_embed;
229#endif 229#endif
230 230
231/* the presence of this union forces similar struct layout */ 231/* the presence of this union forces similar struct layout */
232union ev_any_watcher 232union ev_any_watcher
233{ 233{
240 struct ev_idle idle; 240 struct ev_idle idle;
241 struct ev_prepare prepare; 241 struct ev_prepare prepare;
242 struct ev_check check; 242 struct ev_check check;
243 struct ev_signal signal; 243 struct ev_signal signal;
244 struct ev_child child; 244 struct ev_child child;
245#if EV_MULTIPLICITY
245 struct ev_embed embed; 246 struct ev_embed embed;
247#endif
246}; 248};
247 249
248/* bits for ev_default_loop and ev_loop_new */ 250/* bits for ev_default_loop and ev_loop_new */
249/* the default */ 251/* the default */
250#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ 252#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */
327unsigned int ev_backend (EV_P); 329unsigned int ev_backend (EV_P);
328#endif 330#endif
329 331
330#define EVLOOP_NONBLOCK 1 /* do not block/wait */ 332#define EVLOOP_NONBLOCK 1 /* do not block/wait */
331#define EVLOOP_ONESHOT 2 /* block *once* only */ 333#define EVLOOP_ONESHOT 2 /* block *once* only */
334#define EVUNLOOP_CANCEL 0 /* undo unloop */
332#define EVUNLOOP_ONE 1 /* unloop once */ 335#define EVUNLOOP_ONE 1 /* unloop once */
333#define EVUNLOOP_ALL 2 /* unloop all loops */ 336#define EVUNLOOP_ALL 2 /* unloop all loops */
334 337
335#if EV_PROTOTYPES 338#if EV_PROTOTYPES
336void ev_loop (EV_P_ int flags); 339void ev_loop (EV_P_ int flags);
350#endif 353#endif
351 354
352/* these may evaluate ev multiple times, and the other arguments at most once */ 355/* these may evaluate ev multiple times, and the other arguments at most once */
353/* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ 356/* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */
354#define ev_init(ev,cb_) do { \ 357#define ev_init(ev,cb_) do { \
355 ((struct ev_watcher *)(void *)(ev))->active = \ 358 ((ev_watcher *)(void *)(ev))->active = \
356 ((struct ev_watcher *)(void *)(ev))->pending = \ 359 ((ev_watcher *)(void *)(ev))->pending = \
357 ((struct ev_watcher *)(void *)(ev))->priority = 0; \ 360 ((ev_watcher *)(void *)(ev))->priority = 0; \
358 ev_set_cb ((ev), cb_); \ 361 ev_set_cb ((ev), cb_); \
359} while (0) 362} while (0)
360 363
361#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 364#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
362#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) 365#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0)
376#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) 379#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0)
377#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) 380#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0)
378#define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) 381#define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0)
379#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0) 382#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0)
380 383
381#define ev_is_pending(ev) (0 + ((struct ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ 384#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
382#define ev_is_active(ev) (0 + ((struct ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ 385#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
383 386
384#define ev_priority(ev) ((struct ev_watcher *)(void *)(ev))->priority /* rw */ 387#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */
385#define ev_cb(ev) (ev)->cb /* rw */ 388#define ev_cb(ev) (ev)->cb /* rw */
386#define ev_set_priority(ev,pri) ev_priority (ev) = (pri) 389#define ev_set_priority(ev,pri) ev_priority (ev) = (pri)
387 390
388#ifndef ev_set_cb 391#ifndef ev_set_cb
389# define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) 392# define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_)
397/* accepts any ev_watcher type */ 400/* accepts any ev_watcher type */
398void ev_feed_event (EV_P_ void *w, int revents); 401void ev_feed_event (EV_P_ void *w, int revents);
399void ev_feed_fd_event (EV_P_ int fd, int revents); 402void ev_feed_fd_event (EV_P_ int fd, int revents);
400void ev_feed_signal_event (EV_P_ int signum); 403void ev_feed_signal_event (EV_P_ int signum);
401 404
402void ev_io_start (EV_P_ struct ev_io *w); 405void ev_io_start (EV_P_ ev_io *w);
403void ev_io_stop (EV_P_ struct ev_io *w); 406void ev_io_stop (EV_P_ ev_io *w);
404 407
405void ev_timer_start (EV_P_ struct ev_timer *w); 408void ev_timer_start (EV_P_ ev_timer *w);
406void ev_timer_stop (EV_P_ struct ev_timer *w); 409void ev_timer_stop (EV_P_ ev_timer *w);
407/* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ 410/* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */
408void ev_timer_again (EV_P_ struct ev_timer *w); 411void ev_timer_again (EV_P_ ev_timer *w);
409 412
410#if EV_PERIODICS 413#if EV_PERIODICS
411void ev_periodic_start (EV_P_ struct ev_periodic *w); 414void ev_periodic_start (EV_P_ ev_periodic *w);
412void ev_periodic_stop (EV_P_ struct ev_periodic *w); 415void ev_periodic_stop (EV_P_ ev_periodic *w);
413void ev_periodic_again (EV_P_ struct ev_periodic *w); 416void ev_periodic_again (EV_P_ ev_periodic *w);
414#endif 417#endif
415 418
416void ev_idle_start (EV_P_ struct ev_idle *w); 419void ev_idle_start (EV_P_ ev_idle *w);
417void ev_idle_stop (EV_P_ struct ev_idle *w); 420void ev_idle_stop (EV_P_ ev_idle *w);
418 421
419void ev_prepare_start (EV_P_ struct ev_prepare *w); 422void ev_prepare_start (EV_P_ ev_prepare *w);
420void ev_prepare_stop (EV_P_ struct ev_prepare *w); 423void ev_prepare_stop (EV_P_ ev_prepare *w);
421 424
422void ev_check_start (EV_P_ struct ev_check *w); 425void ev_check_start (EV_P_ ev_check *w);
423void ev_check_stop (EV_P_ struct ev_check *w); 426void ev_check_stop (EV_P_ ev_check *w);
424 427
425/* only supported in the default loop */ 428/* only supported in the default loop */
426void ev_signal_start (EV_P_ struct ev_signal *w); 429void ev_signal_start (EV_P_ ev_signal *w);
427void ev_signal_stop (EV_P_ struct ev_signal *w); 430void ev_signal_stop (EV_P_ ev_signal *w);
428 431
429/* only supported in the default loop */ 432/* only supported in the default loop */
430void ev_child_start (EV_P_ struct ev_child *w); 433void ev_child_start (EV_P_ ev_child *w);
431void ev_child_stop (EV_P_ struct ev_child *w); 434void ev_child_stop (EV_P_ ev_child *w);
432 435
433# if EV_MULTIPLICITY 436# if EV_MULTIPLICITY
434/* only supported when loop to be embedded is in fact embeddable */ 437/* only supported when loop to be embedded is in fact embeddable */
435void ev_embed_start (EV_P_ struct ev_embed *w); 438void ev_embed_start (EV_P_ ev_embed *w);
436void ev_embed_stop (EV_P_ struct ev_embed *w); 439void ev_embed_stop (EV_P_ ev_embed *w);
440void ev_embed_loop (EV_P_ ev_embed *w);
437# endif 441# endif
438 442
439#endif 443#endif
440 444
441#ifdef __cplusplus 445#ifdef __cplusplus

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines