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.79 by root, Sat Dec 8 03:53:36 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
240 242
241 int wd; /* wd for inotify, fd for kqueue */ 243 int wd; /* wd for inotify, fd for kqueue */
242} ev_stat; 244} ev_stat;
243#endif 245#endif
244 246
247#if EV_IDLE_ENABLE
245/* invoked when the nothing else needs to be done, keeps the process from blocking */ 248/* invoked when the nothing else needs to be done, keeps the process from blocking */
246/* revent EV_IDLE */ 249/* revent EV_IDLE */
247typedef struct ev_idle 250typedef struct ev_idle
248{ 251{
249 EV_WATCHER (ev_idle) 252 EV_WATCHER (ev_idle)
250} ev_idle; 253} ev_idle;
254#endif
251 255
252/* invoked for each run of the mainloop, just before the blocking call */ 256/* invoked for each run of the mainloop, just before the blocking call */
253/* you can still change events in any way you like */ 257/* you can still change events in any way you like */
254/* revent EV_PREPARE */ 258/* revent EV_PREPARE */
255typedef struct ev_prepare 259typedef struct ev_prepare
296 struct ev_signal signal; 300 struct ev_signal signal;
297 struct ev_child child; 301 struct ev_child child;
298#if EV_STAT_ENABLE 302#if EV_STAT_ENABLE
299 struct ev_stat stat; 303 struct ev_stat stat;
300#endif 304#endif
305#if EV_IDLE_ENABLE
301 struct ev_idle idle; 306 struct ev_idle idle;
307#endif
302 struct ev_prepare prepare; 308 struct ev_prepare prepare;
303 struct ev_check check; 309 struct ev_check check;
304#if EV_FORK_ENABLE 310#if EV_FORK_ENABLE
305 struct ev_fork fork; 311 struct ev_fork fork;
306#endif 312#endif
312/* bits for ev_default_loop and ev_loop_new */ 318/* bits for ev_default_loop and ev_loop_new */
313/* the default */ 319/* the default */
314#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ 320#define EVFLAG_AUTO 0x00000000UL /* not quite a mask */
315/* flag bits */ 321/* flag bits */
316#define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ 322#define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */
323#define EVFLAG_FORKCHECK 0x02000000UL /* check for a fork in each iteration */
317/* method bits to be ored together */ 324/* method bits to be ored together */
318#define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ 325#define EVBACKEND_SELECT 0x00000001UL /* about anywhere */
319#define EVBACKEND_POLL 0x00000002UL /* !win */ 326#define EVBACKEND_POLL 0x00000002UL /* !win */
320#define EVBACKEND_EPOLL 0x00000004UL /* linux */ 327#define EVBACKEND_EPOLL 0x00000004UL /* linux */
321#define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ 328#define EVBACKEND_KQUEUE 0x00000008UL /* bsd */
336 * It is used to allocate and free memory. 343 * It is used to allocate and free memory.
337 * If it returns zero when memory needs to be allocated, the library might abort 344 * If it returns zero when memory needs to be allocated, the library might abort
338 * or take some potentially destructive action. 345 * or take some potentially destructive action.
339 * The default is your system realloc function. 346 * The default is your system realloc function.
340 */ 347 */
341void ev_set_allocator (void *(*cb)(void *ptr, size_t size)); 348void ev_set_allocator (void *(*cb)(void *ptr, long size));
342 349
343/* set the callback function to call on a 350/* set the callback function to call on a
344 * retryable syscall error 351 * retryable syscall error
345 * (such as failed select, poll, epoll_wait) 352 * (such as failed select, poll, epoll_wait)
346 */ 353 */
387/* you can call it in either the parent or the child */ 394/* you can call it in either the parent or the child */
388/* you can actually call it at any time, anywhere :) */ 395/* you can actually call it at any time, anywhere :) */
389void ev_default_fork (void); 396void ev_default_fork (void);
390 397
391unsigned int ev_backend (EV_P); 398unsigned int ev_backend (EV_P);
399unsigned int ev_loop_count (EV_P);
392#endif 400#endif
393 401
394#define EVLOOP_NONBLOCK 1 /* do not block/wait */ 402#define EVLOOP_NONBLOCK 1 /* do not block/wait */
395#define EVLOOP_ONESHOT 2 /* block *once* only */ 403#define EVLOOP_ONESHOT 2 /* block *once* only */
396#define EVUNLOOP_CANCEL 0 /* undo unloop */ 404#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); 422void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
415#endif 423#endif
416 424
417/* these may evaluate ev multiple times, and the other arguments at most once */ 425/* 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 */ 426/* 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 { \ 427#define ev_init(ev,cb_) do { \
420 ((ev_watcher *)(void *)(ev))->active = \ 428 ((ev_watcher *)(void *)(ev))->active = \
421 ((ev_watcher *)(void *)(ev))->pending = \ 429 ((ev_watcher *)(void *)(ev))->pending = \
422 ((ev_watcher *)(void *)(ev))->priority = 0; \ 430 ((ev_watcher *)(void *)(ev))->priority = 0; \
423 ev_set_cb ((ev), cb_); \ 431 ev_set_cb ((ev), cb_); \
424} while (0) 432} while (0)
425 433
426#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 434#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
427#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) 435#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) 436#define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0)
448#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) 456#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0)
449 457
450#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ 458#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 */ 459#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
452 460
453#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ 461#define ev_priority(ev) ((((ev_watcher *)(void *)(ev))->priority) + 0)
454#define ev_cb(ev) (ev)->cb /* rw */ 462#define ev_cb(ev) (ev)->cb /* rw */
455#define ev_set_priority(ev,pri) ev_priority (ev) = (pri) 463#define ev_set_priority(ev,pri) ((ev_watcher *)(void *)(ev))->priority = (pri)
456 464
457#ifndef ev_set_cb 465#ifndef ev_set_cb
458# define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) 466# define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_)
459#endif 467#endif
460 468
465/* feeds an event into a watcher as if the event actually occured */ 473/* feeds an event into a watcher as if the event actually occured */
466/* accepts any ev_watcher type */ 474/* accepts any ev_watcher type */
467void ev_feed_event (EV_P_ void *w, int revents); 475void ev_feed_event (EV_P_ void *w, int revents);
468void ev_feed_fd_event (EV_P_ int fd, int revents); 476void ev_feed_fd_event (EV_P_ int fd, int revents);
469void ev_feed_signal_event (EV_P_ int signum); 477void ev_feed_signal_event (EV_P_ int signum);
478void ev_clear_pending (EV_P_ void *w, int invoke);
470 479
471void ev_io_start (EV_P_ ev_io *w); 480void ev_io_start (EV_P_ ev_io *w);
472void ev_io_stop (EV_P_ ev_io *w); 481void ev_io_stop (EV_P_ ev_io *w);
473 482
474void ev_timer_start (EV_P_ ev_timer *w); 483void ev_timer_start (EV_P_ ev_timer *w);
494void ev_stat_start (EV_P_ ev_stat *w); 503void ev_stat_start (EV_P_ ev_stat *w);
495void ev_stat_stop (EV_P_ ev_stat *w); 504void ev_stat_stop (EV_P_ ev_stat *w);
496void ev_stat_stat (EV_P_ ev_stat *w); 505void ev_stat_stat (EV_P_ ev_stat *w);
497# endif 506# endif
498 507
508# if EV_IDLE_ENABLE
499void ev_idle_start (EV_P_ ev_idle *w); 509void ev_idle_start (EV_P_ ev_idle *w);
500void ev_idle_stop (EV_P_ ev_idle *w); 510void ev_idle_stop (EV_P_ ev_idle *w);
511# endif
501 512
502void ev_prepare_start (EV_P_ ev_prepare *w); 513void ev_prepare_start (EV_P_ ev_prepare *w);
503void ev_prepare_stop (EV_P_ ev_prepare *w); 514void ev_prepare_stop (EV_P_ ev_prepare *w);
504 515
505void ev_check_start (EV_P_ ev_check *w); 516void ev_check_start (EV_P_ ev_check *w);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines