ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.h
Revision: 1.5
Committed: Wed Oct 31 07:24:17 2007 UTC (16 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.4: +37 -18 lines
Log Message:
implement idle and check watchers, rmeove flawed hook system

File Contents

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