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

Comparing libev/ev.h (file contents):
Revision 1.4 by root, Wed Oct 31 00:32:33 2007 UTC vs.
Revision 1.5 by root, Wed Oct 31 07:24:17 2007 UTC

3 3
4typedef double ev_tstamp; 4typedef double ev_tstamp;
5 5
6/* eventmask, revents, events... */ 6/* eventmask, revents, events... */
7#define EV_UNDEF -1 /* guaranteed to be invalid */ 7#define EV_UNDEF -1 /* guaranteed to be invalid */
8#define EV_NONE 0 8#define EV_NONE 0x00
9#define EV_READ 1 9#define EV_READ 0x01
10#define EV_WRITE 2 10#define EV_WRITE 0x02
11#define EV_TIMEOUT 4 11#define EV_TIMEOUT 0x04
12#define EV_SIGNAL 8 12#define EV_SIGNAL 0x08
13#define EV_IDLE 0x10
14#define EV_CHECK 0x20
13 15
14/* shared by all watchers */ 16/* shared by all watchers */
15#define EV_WATCHER(type) \ 17#define EV_WATCHER(type) \
16 int active; /* private */ \ 18 int active; /* private */ \
17 int pending; /* private */ \ 19 int pending; /* private */ \
18 void *data; /* rw */ \ 20 void *data; /* rw */ \
19 void (*cb)(struct type *, int revents) /* rw */ 21 void (*cb)(struct type *, int revents) /* rw */ /* gets invoked with an eventmask */
20 22
21#define EV_WATCHER_LIST(type) \ 23#define EV_WATCHER_LIST(type) \
22 EV_WATCHER (type); \ 24 EV_WATCHER (type); \
23 struct type *next /* private */ 25 struct type *next /* private */
24 26
27/* invoked at a specific time or after a specific time, repeatable */
25struct ev_timer 28struct ev_timer
26{ 29{
27 EV_WATCHER_LIST (ev_timer); 30 EV_WATCHER_LIST (ev_timer);
28 31
29 ev_tstamp at; /* private */ 32 ev_tstamp at; /* private */
30 ev_tstamp repeat; /* rw */ 33 ev_tstamp repeat; /* rw */
31 unsigned char is_abs; /* ro */ 34 unsigned char is_abs; /* ro */
32}; 35};
33 36
37/* invoked when fd is either EV_READable or EV_WRITEable */
34struct ev_io 38struct ev_io
35{ 39{
36 EV_WATCHER_LIST (ev_io); 40 EV_WATCHER_LIST (ev_io);
37 41
38 int fd; /* ro */ 42 int fd; /* ro */
39 int events; /* ro */ 43 int events; /* ro */
40}; 44};
41 45
46/* invoked when the given signal has been received */
42struct ev_signal 47struct ev_signal
43{ 48{
44 EV_WATCHER_LIST (ev_signal); 49 EV_WATCHER_LIST (ev_signal);
45 50
46 int signum; /* ro */ 51 int signum; /* ro */
47}; 52};
48 53
54/* invoked when the nothing else needs to be done, keeps the process from blocking */
55struct ev_idle
56{
57 EV_WATCHER (ev_idle);
58};
59
60/* invoked for each run of the mainloop, just before the next blocking vall is initiated */
61struct ev_check
62{
63 EV_WATCHER (ev_check);
64};
65
49#define EVMETHOD_NONE 0 66#define EVMETHOD_NONE 0
50#define EVMETHOD_SELECT 1 67#define EVMETHOD_SELECT 1
51#define EVMETHOD_EPOLL 2 68#define EVMETHOD_EPOLL 2
52int ev_init (int flags); 69int ev_init (int flags); /* returns ev_method */
53extern int ev_method; 70extern int ev_method;
54 71
72/* these three calls are suitable for plugging into pthread_atfork */
55void ev_prefork (void); 73void ev_prefork (void);
56void ev_postfork_parent (void); 74void ev_postfork_parent (void);
57void ev_postfork_child (void); 75void ev_postfork_child (void);
58 76
59extern ev_tstamp ev_now; /* time w.r.t. timers and the eventloop, updated after each poll */ 77extern ev_tstamp ev_now; /* time w.r.t. timers and the eventloop, updated after each poll */
62#define EVLOOP_NONBLOCK 1 /* do not block/wait */ 80#define EVLOOP_NONBLOCK 1 /* do not block/wait */
63#define EVLOOP_ONESHOT 2 /* block *once* only */ 81#define EVLOOP_ONESHOT 2 /* block *once* only */
64void ev_loop (int flags); 82void ev_loop (int flags);
65extern int ev_loop_done; /* set to 1 to break out of event loop */ 83extern int ev_loop_done; /* set to 1 to break out of event loop */
66 84
67#define EVHOOK_PREPOLL 0 /* called before updating fds, timers and blocking */
68#define EVHOOK_POSTPOLL 1 /* called after blocking */
69#define EVHOOK_NUM 2 /* just the # of hooks */
70typedef void (*ev_hook)(void);
71void ev_hook_register (int type, ev_hook hook);
72void ev_hook_unregister (int type, ev_hook hook);
73
74/* these may evaluate ev multiple times, and the other arguments at most once */ 85/* these may evaluate ev multiple times, and the other arguments at most once */
75#define evw_init(ev,cb_,data_) do { (ev)->active = 0; (ev)->cb = (cb_); (ev)->data = (void *)data_; } while (0) 86#define evw_init(ev,cb_,data_) do { (ev)->active = 0; (ev)->cb = (cb_); (ev)->data = (void *)data_; } while (0)
76 87
77#define evio_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 88#define evio_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
78#define evtimer_set_rel(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); (ev)->is_abs = 0; } while (0) 89#define evtimer_set_rel(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); (ev)->is_abs = 0; } while (0)
79#define evtimer_set_abs(ev,at_,repeat_) do { (ev)->at = (at_); (ev)->repeat = (repeat_); (ev)->is_abs = 1; } while (0) 90#define evtimer_set_abs(ev,at_,repeat_) do { (ev)->at = (at_); (ev)->repeat = (repeat_); (ev)->is_abs = 1; } while (0)
80#define evsignal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) 91#define evsignal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
81 92
82#define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ 93#define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */
83 94
95/* stopping (enabling, adding) a watcher does nothing if it is already running */
96/* stopping (disabling, deleting) a watcher does nothing unless its already running */
84void evio_start (struct ev_io *w); 97void evio_start (struct ev_io *w);
85void evio_stop (struct ev_io *w); 98void evio_stop (struct ev_io *w);
86 99
87void evtimer_start (struct ev_timer *w); 100void evtimer_start (struct ev_timer *w);
88void evtimer_stop (struct ev_timer *w); 101void evtimer_stop (struct ev_timer *w);
89 102
90void evsignal_start (struct ev_signal *w); 103void evsignal_start (struct ev_signal *w);
91void evsignal_stop (struct ev_signal *w); 104void evsignal_stop (struct ev_signal *w);
92 105
106void evidle_start (struct ev_idle *w);
107void evidle_stop (struct ev_idle *w);
108
109void evcheck_start (struct ev_check *w);
110void evcheck_stop (struct ev_check *w);
111
93#endif 112#endif
94 113

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines