1 |
root |
1.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 |
root |
1.5 |
#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 |
root |
1.1 |
|
16 |
|
|
/* shared by all watchers */ |
17 |
|
|
#define EV_WATCHER(type) \ |
18 |
|
|
int active; /* private */ \ |
19 |
|
|
int pending; /* private */ \ |
20 |
|
|
void *data; /* rw */ \ |
21 |
root |
1.5 |
void (*cb)(struct type *, int revents) /* rw */ /* gets invoked with an eventmask */ |
22 |
root |
1.1 |
|
23 |
|
|
#define EV_WATCHER_LIST(type) \ |
24 |
|
|
EV_WATCHER (type); \ |
25 |
|
|
struct type *next /* private */ |
26 |
|
|
|
27 |
root |
1.5 |
/* invoked at a specific time or after a specific time, repeatable */ |
28 |
root |
1.1 |
struct ev_timer |
29 |
|
|
{ |
30 |
|
|
EV_WATCHER_LIST (ev_timer); |
31 |
|
|
|
32 |
root |
1.3 |
ev_tstamp at; /* private */ |
33 |
root |
1.1 |
ev_tstamp repeat; /* rw */ |
34 |
root |
1.3 |
unsigned char is_abs; /* ro */ |
35 |
root |
1.1 |
}; |
36 |
|
|
|
37 |
root |
1.5 |
/* invoked when fd is either EV_READable or EV_WRITEable */ |
38 |
root |
1.1 |
struct ev_io |
39 |
|
|
{ |
40 |
|
|
EV_WATCHER_LIST (ev_io); |
41 |
|
|
|
42 |
|
|
int fd; /* ro */ |
43 |
|
|
int events; /* ro */ |
44 |
|
|
}; |
45 |
|
|
|
46 |
root |
1.5 |
/* invoked when the given signal has been received */ |
47 |
root |
1.1 |
struct ev_signal |
48 |
|
|
{ |
49 |
|
|
EV_WATCHER_LIST (ev_signal); |
50 |
|
|
|
51 |
|
|
int signum; /* ro */ |
52 |
|
|
}; |
53 |
|
|
|
54 |
root |
1.5 |
/* 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 |
root |
1.1 |
#define EVMETHOD_NONE 0 |
67 |
|
|
#define EVMETHOD_SELECT 1 |
68 |
|
|
#define EVMETHOD_EPOLL 2 |
69 |
root |
1.5 |
int ev_init (int flags); /* returns ev_method */ |
70 |
root |
1.1 |
extern int ev_method; |
71 |
|
|
|
72 |
root |
1.5 |
/* these three calls are suitable for plugging into pthread_atfork */ |
73 |
root |
1.1 |
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 |
root |
1.3 |
void ev_loop (int flags); |
83 |
root |
1.1 |
extern int ev_loop_done; /* set to 1 to break out of event loop */ |
84 |
|
|
|
85 |
root |
1.2 |
/* these may evaluate ev multiple times, and the other arguments at most once */ |
86 |
root |
1.1 |
#define evw_init(ev,cb_,data_) do { (ev)->active = 0; (ev)->cb = (cb_); (ev)->data = (void *)data_; } while (0) |
87 |
root |
1.3 |
|
88 |
root |
1.1 |
#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 |
root |
1.2 |
#define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ |
94 |
root |
1.1 |
|
95 |
root |
1.5 |
/* 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 |
root |
1.1 |
|
100 |
root |
1.5 |
void evtimer_start (struct ev_timer *w); |
101 |
|
|
void evtimer_stop (struct ev_timer *w); |
102 |
root |
1.1 |
|
103 |
|
|
void evsignal_start (struct ev_signal *w); |
104 |
|
|
void evsignal_stop (struct ev_signal *w); |
105 |
|
|
|
106 |
root |
1.5 |
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 |
root |
1.1 |
#endif |
113 |
|
|
|