Mirror of :pserver:anonymous@cvs.schmorp.de/schmorpforge libev http://software.schmorp.de/pkg/libev.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

14 years ago
14 years ago
14 years ago
14 years ago
  1. #ifndef EV_H
  2. #define EV_H
  3. typedef double ev_tstamp;
  4. /* eventmask, revents, events... */
  5. #define EV_UNDEF -1 /* guaranteed to be invalid */
  6. #define EV_NONE 0
  7. #define EV_READ 1
  8. #define EV_WRITE 2
  9. #define EV_TIMEOUT 4
  10. #define EV_SIGNAL 8
  11. /* shared by all watchers */
  12. #define EV_WATCHER(type) \
  13. int active; /* private */ \
  14. int pending; /* private */ \
  15. void *data; /* rw */ \
  16. void (*cb)(struct type *, int revents) /* rw */
  17. #define EV_WATCHER_LIST(type) \
  18. EV_WATCHER (type); \
  19. struct type *next /* private */
  20. struct ev_timer
  21. {
  22. EV_WATCHER_LIST (ev_timer);
  23. ev_tstamp at; /* private */
  24. ev_tstamp repeat; /* rw */
  25. unsigned char is_abs; /* ro */
  26. };
  27. struct ev_io
  28. {
  29. EV_WATCHER_LIST (ev_io);
  30. int fd; /* ro */
  31. int events; /* ro */
  32. };
  33. struct ev_signal
  34. {
  35. EV_WATCHER_LIST (ev_signal);
  36. int signum; /* ro */
  37. };
  38. #define EVMETHOD_NONE 0
  39. #define EVMETHOD_SELECT 1
  40. #define EVMETHOD_EPOLL 2
  41. int ev_init (int flags);
  42. extern int ev_method;
  43. void ev_prefork (void);
  44. void ev_postfork_parent (void);
  45. void ev_postfork_child (void);
  46. extern ev_tstamp ev_now; /* time w.r.t. timers and the eventloop, updated after each poll */
  47. ev_tstamp ev_time (void);
  48. #define EVLOOP_NONBLOCK 1 /* do not block/wait */
  49. #define EVLOOP_ONESHOT 2 /* block *once* only */
  50. void ev_loop (int flags);
  51. extern int ev_loop_done; /* set to 1 to break out of event loop */
  52. /* these may evaluate ev multiple times, and the other arguments at most once */
  53. #define evw_init(ev,cb_,data_) do { (ev)->active = 0; (ev)->cb = (cb_); (ev)->data = (void *)data_; } while (0)
  54. #define evio_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
  55. #define evtimer_set_rel(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); (ev)->is_abs = 0; } while (0)
  56. #define evtimer_set_abs(ev,at_,repeat_) do { (ev)->at = (at_); (ev)->repeat = (repeat_); (ev)->is_abs = 1; } while (0)
  57. #define evsignal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
  58. #define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */
  59. void evio_start (struct ev_io *w);
  60. void evio_stop (struct ev_io *w);
  61. void evtimer_start (struct ev_timer *w);
  62. void evtimer_stop (struct ev_timer *w);
  63. void evsignal_start (struct ev_signal *w);
  64. void evsignal_stop (struct ev_signal *w);
  65. #endif