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

Comparing libev/ev.h (file contents):
Revision 1.74 by root, Wed Nov 28 11:15:55 2007 UTC vs.
Revision 1.87 by root, Thu Dec 20 10:12:22 2007 UTC

54 54
55#ifndef EV_STAT_ENABLE 55#ifndef EV_STAT_ENABLE
56# define EV_STAT_ENABLE 1 56# define EV_STAT_ENABLE 1
57#endif 57#endif
58 58
59#ifndef EV_IDLE_ENABLE
60# define EV_IDLE_ENABLE 1
61#endif
62
59#ifndef EV_FORK_ENABLE 63#ifndef EV_FORK_ENABLE
60# define EV_FORK_ENABLE 1 64# define EV_FORK_ENABLE 1
61#endif 65#endif
62 66
63#ifndef EV_EMBED_ENABLE 67#ifndef EV_EMBED_ENABLE
64# define EV_EMBED_ENABLE 1 68# define EV_EMBED_ENABLE 1
65#endif 69#endif
66 70
67/*****************************************************************************/ 71/*****************************************************************************/
68
69#include <stddef.h> /* for size_t */
70 72
71#if EV_STAT_ENABLE 73#if EV_STAT_ENABLE
72# include <sys/stat.h> 74# include <sys/stat.h>
73#endif 75#endif
74 76
95/* eventmask, revents, events... */ 97/* eventmask, revents, events... */
96#define EV_UNDEF -1L /* guaranteed to be invalid */ 98#define EV_UNDEF -1L /* guaranteed to be invalid */
97#define EV_NONE 0x00L /* no events */ 99#define EV_NONE 0x00L /* no events */
98#define EV_READ 0x01L /* ev_io detected read will not block */ 100#define EV_READ 0x01L /* ev_io detected read will not block */
99#define EV_WRITE 0x02L /* ev_io detected write will not block */ 101#define EV_WRITE 0x02L /* ev_io detected write will not block */
102#define EV_IOFDSET 0x80L /* internal use only */
100#define EV_TIMEOUT 0x00000100L /* timer timed out */ 103#define EV_TIMEOUT 0x00000100L /* timer timed out */
101#define EV_PERIODIC 0x00000200L /* periodic timer timed out */ 104#define EV_PERIODIC 0x00000200L /* periodic timer timed out */
102#define EV_SIGNAL 0x00000400L /* signal was received */ 105#define EV_SIGNAL 0x00000400L /* signal was received */
103#define EV_CHILD 0x00000800L /* child/pid had status change */ 106#define EV_CHILD 0x00000800L /* child/pid had status change */
104#define EV_STAT 0x00001000L /* stat data changed */ 107#define EV_STAT 0x00001000L /* stat data changed */
115#endif 118#endif
116#ifndef EV_PROTOTYPES 119#ifndef EV_PROTOTYPES
117# define EV_PROTOTYPES 1 120# define EV_PROTOTYPES 1
118#endif 121#endif
119 122
120#define EV_VERSION_MAJOR 1 123#define EV_VERSION_MAJOR 2
121#define EV_VERSION_MINOR 1 124#define EV_VERSION_MINOR 0
122 125
123#ifndef EV_CB_DECLARE 126#ifndef EV_CB_DECLARE
124# define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents); 127# define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents);
125#endif 128#endif
126#ifndef EV_CB_INVOKE 129#ifndef EV_CB_INVOKE
191/* revent EV_PERIODIC */ 194/* revent EV_PERIODIC */
192typedef struct ev_periodic 195typedef struct ev_periodic
193{ 196{
194 EV_WATCHER_TIME (ev_periodic) 197 EV_WATCHER_TIME (ev_periodic)
195 198
199 ev_tstamp offset; /* rw */
196 ev_tstamp interval; /* rw */ 200 ev_tstamp interval; /* rw */
197 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ 201 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */
198} ev_periodic; 202} ev_periodic;
199 203
200/* invoked when the given signal has been received */ 204/* invoked when the given signal has been received */
240 244
241 int wd; /* wd for inotify, fd for kqueue */ 245 int wd; /* wd for inotify, fd for kqueue */
242} ev_stat; 246} ev_stat;
243#endif 247#endif
244 248
249#if EV_IDLE_ENABLE
245/* invoked when the nothing else needs to be done, keeps the process from blocking */ 250/* invoked when the nothing else needs to be done, keeps the process from blocking */
246/* revent EV_IDLE */ 251/* revent EV_IDLE */
247typedef struct ev_idle 252typedef struct ev_idle
248{ 253{
249 EV_WATCHER (ev_idle) 254 EV_WATCHER (ev_idle)
250} ev_idle; 255} ev_idle;
256#endif
251 257
252/* invoked for each run of the mainloop, just before the blocking call */ 258/* invoked for each run of the mainloop, just before the blocking call */
253/* you can still change events in any way you like */ 259/* you can still change events in any way you like */
254/* revent EV_PREPARE */ 260/* revent EV_PREPARE */
255typedef struct ev_prepare 261typedef struct ev_prepare
277/* the callback gets invoked when the event loop has handled events, and can be 0 */ 283/* the callback gets invoked when the event loop has handled events, and can be 0 */
278typedef struct ev_embed 284typedef struct ev_embed
279{ 285{
280 EV_WATCHER (ev_embed) 286 EV_WATCHER (ev_embed)
281 287
282 ev_io io; /* private */
283 struct ev_loop *loop; /* ro */ 288 struct ev_loop *other; /* ro */
289 ev_io io; /* private */
290 ev_prepare prepare; /* private */
291 ev_check check; /* unused */
292 ev_timer timer; /* unused */
293 ev_periodic periodic; /* unused */
294 ev_idle idle; /* unused */
295 ev_fork fork; /* unused */
284} ev_embed; 296} ev_embed;
285#endif 297#endif
286 298
287/* the presence of this union forces similar struct layout */ 299/* the presence of this union forces similar struct layout */
288union ev_any_watcher 300union ev_any_watcher
296 struct ev_signal signal; 308 struct ev_signal signal;
297 struct ev_child child; 309 struct ev_child child;
298#if EV_STAT_ENABLE 310#if EV_STAT_ENABLE
299 struct ev_stat stat; 311 struct ev_stat stat;
300#endif 312#endif
313#if EV_IDLE_ENABLE
301 struct ev_idle idle; 314 struct ev_idle idle;
315#endif
302 struct ev_prepare prepare; 316 struct ev_prepare prepare;
303 struct ev_check check; 317 struct ev_check check;
304#if EV_FORK_ENABLE 318#if EV_FORK_ENABLE
305 struct ev_fork fork; 319 struct ev_fork fork;
306#endif 320#endif
312/* bits for ev_default_loop and ev_loop_new */ 326/* bits for ev_default_loop and ev_loop_new */
313/* the default */ 327/* the default */
314#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ 328#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */
315/* flag bits */ 329/* flag bits */
316#define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ 330#define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */
331#define EVFLAG_FORKCHECK 0x02000000UL /* check for a fork in each iteration */
317/* method bits to be ored together */ 332/* method bits to be ored together */
318#define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ 333#define EVBACKEND_SELECT 0x00000001UL /* about anywhere */
319#define EVBACKEND_POLL 0x00000002UL /* !win */ 334#define EVBACKEND_POLL 0x00000002UL /* !win */
320#define EVBACKEND_EPOLL 0x00000004UL /* linux */ 335#define EVBACKEND_EPOLL 0x00000004UL /* linux */
321#define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ 336#define EVBACKEND_KQUEUE 0x00000008UL /* bsd */
336 * It is used to allocate and free memory. 351 * It is used to allocate and free memory.
337 * If it returns zero when memory needs to be allocated, the library might abort 352 * If it returns zero when memory needs to be allocated, the library might abort
338 * or take some potentially destructive action. 353 * or take some potentially destructive action.
339 * The default is your system realloc function. 354 * The default is your system realloc function.
340 */ 355 */
341void ev_set_allocator (void *(*cb)(void *ptr, size_t size)); 356void ev_set_allocator (void *(*cb)(void *ptr, long size));
342 357
343/* set the callback function to call on a 358/* set the callback function to call on a
344 * retryable syscall error 359 * retryable syscall error
345 * (such as failed select, poll, epoll_wait) 360 * (such as failed select, poll, epoll_wait)
346 */ 361 */
387/* you can call it in either the parent or the child */ 402/* you can call it in either the parent or the child */
388/* you can actually call it at any time, anywhere :) */ 403/* you can actually call it at any time, anywhere :) */
389void ev_default_fork (void); 404void ev_default_fork (void);
390 405
391unsigned int ev_backend (EV_P); 406unsigned int ev_backend (EV_P);
407unsigned int ev_loop_count (EV_P);
392#endif 408#endif
393 409
394#define EVLOOP_NONBLOCK 1 /* do not block/wait */ 410#define EVLOOP_NONBLOCK 1 /* do not block/wait */
395#define EVLOOP_ONESHOT 2 /* block *once* only */ 411#define EVLOOP_ONESHOT 2 /* block *once* only */
396#define EVUNLOOP_CANCEL 0 /* undo unloop */ 412#define EVUNLOOP_CANCEL 0 /* undo unloop */
414void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); 430void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
415#endif 431#endif
416 432
417/* these may evaluate ev multiple times, and the other arguments at most once */ 433/* these may evaluate ev multiple times, and the other arguments at most once */
418/* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ 434/* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */
419#define ev_init(ev,cb_) do { \ 435#define ev_init(ev,cb_) do { \
420 ((ev_watcher *)(void *)(ev))->active = \ 436 ((ev_watcher *)(void *)(ev))->active = \
421 ((ev_watcher *)(void *)(ev))->pending = \ 437 ((ev_watcher *)(void *)(ev))->pending = \
422 ((ev_watcher *)(void *)(ev))->priority = 0; \ 438 ((ev_watcher *)(void *)(ev))->priority = 0; \
423 ev_set_cb ((ev), cb_); \ 439 ev_set_cb ((ev), cb_); \
424} while (0) 440} while (0)
425 441
426#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 442#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_) | EV_IOFDSET; } while (0)
427#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) 443#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0)
428#define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0) 444#define ev_periodic_set(ev,ofs_,ival_,res_) do { (ev)->offset = (ofs_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0)
429#define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) 445#define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
430#define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0) 446#define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0)
431#define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); (ev)->wd = -2; } while (0) 447#define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); (ev)->wd = -2; } while (0)
432#define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ 448#define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */
433#define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ 449#define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */
434#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ 450#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */
435#define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0) 451#define ev_embed_set(ev,other_) do { (ev)->other = (other_); } while (0)
436#define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */ 452#define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */
437 453
438#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0) 454#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0)
439#define ev_timer_init(ev,cb,after,repeat) do { ev_init ((ev), (cb)); ev_timer_set ((ev),(after),(repeat)); } while (0) 455#define ev_timer_init(ev,cb,after,repeat) do { ev_init ((ev), (cb)); ev_timer_set ((ev),(after),(repeat)); } while (0)
440#define ev_periodic_init(ev,cb,at,ival,res) do { ev_init ((ev), (cb)); ev_periodic_set ((ev),(at),(ival),(res)); } while (0) 456#define ev_periodic_init(ev,cb,at,ival,res) do { ev_init ((ev), (cb)); ev_periodic_set ((ev),(at),(ival),(res)); } while (0)
442#define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) 458#define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0)
443#define ev_stat_init(ev,cb,path,interval) do { ev_init ((ev), (cb)); ev_path_set ((ev),(path),(interval)); } while (0) 459#define ev_stat_init(ev,cb,path,interval) do { ev_init ((ev), (cb)); ev_path_set ((ev),(path),(interval)); } while (0)
444#define ev_idle_init(ev,cb) do { ev_init ((ev), (cb)); ev_idle_set ((ev)); } while (0) 460#define ev_idle_init(ev,cb) do { ev_init ((ev), (cb)); ev_idle_set ((ev)); } while (0)
445#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) 461#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0)
446#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) 462#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0)
447#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0) 463#define ev_embed_init(ev,cb,other) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(other)); } while (0)
448#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) 464#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0)
449 465
450#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ 466#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
451#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ 467#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
452 468
453#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ 469#define ev_priority(ev) ((((ev_watcher *)(void *)(ev))->priority) + 0)
454#define ev_cb(ev) (ev)->cb /* rw */ 470#define ev_cb(ev) (ev)->cb /* rw */
455#define ev_set_priority(ev,pri) ev_priority (ev) = (pri) 471#define ev_set_priority(ev,pri) ((ev_watcher *)(void *)(ev))->priority = (pri)
456 472
457#ifndef ev_set_cb 473#ifndef ev_set_cb
458# define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) 474# define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_)
459#endif 475#endif
460 476
465/* feeds an event into a watcher as if the event actually occured */ 481/* feeds an event into a watcher as if the event actually occured */
466/* accepts any ev_watcher type */ 482/* accepts any ev_watcher type */
467void ev_feed_event (EV_P_ void *w, int revents); 483void ev_feed_event (EV_P_ void *w, int revents);
468void ev_feed_fd_event (EV_P_ int fd, int revents); 484void ev_feed_fd_event (EV_P_ int fd, int revents);
469void ev_feed_signal_event (EV_P_ int signum); 485void ev_feed_signal_event (EV_P_ int signum);
486void ev_invoke (EV_P_ void *w, int revents);
487int ev_clear_pending (EV_P_ void *w);
470 488
471void ev_io_start (EV_P_ ev_io *w); 489void ev_io_start (EV_P_ ev_io *w);
472void ev_io_stop (EV_P_ ev_io *w); 490void ev_io_stop (EV_P_ ev_io *w);
473 491
474void ev_timer_start (EV_P_ ev_timer *w); 492void ev_timer_start (EV_P_ ev_timer *w);
494void ev_stat_start (EV_P_ ev_stat *w); 512void ev_stat_start (EV_P_ ev_stat *w);
495void ev_stat_stop (EV_P_ ev_stat *w); 513void ev_stat_stop (EV_P_ ev_stat *w);
496void ev_stat_stat (EV_P_ ev_stat *w); 514void ev_stat_stat (EV_P_ ev_stat *w);
497# endif 515# endif
498 516
517# if EV_IDLE_ENABLE
499void ev_idle_start (EV_P_ ev_idle *w); 518void ev_idle_start (EV_P_ ev_idle *w);
500void ev_idle_stop (EV_P_ ev_idle *w); 519void ev_idle_stop (EV_P_ ev_idle *w);
520# endif
501 521
502void ev_prepare_start (EV_P_ ev_prepare *w); 522void ev_prepare_start (EV_P_ ev_prepare *w);
503void ev_prepare_stop (EV_P_ ev_prepare *w); 523void ev_prepare_stop (EV_P_ ev_prepare *w);
504 524
505void ev_check_start (EV_P_ ev_check *w); 525void ev_check_start (EV_P_ ev_check *w);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines