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

Comparing libev/ev.h (file contents):
Revision 1.6 by root, Wed Oct 31 09:23:18 2007 UTC vs.
Revision 1.9 by root, Wed Oct 31 13:57:34 2007 UTC

10#define EV_WRITE 0x02 10#define EV_WRITE 0x02
11#define EV_TIMEOUT 0x04 11#define EV_TIMEOUT 0x04
12#define EV_SIGNAL 0x08 12#define EV_SIGNAL 0x08
13#define EV_IDLE 0x10 13#define EV_IDLE 0x10
14#define EV_CHECK 0x20 14#define EV_CHECK 0x20
15#define EV_ERROR (0x3f|0x80)
15 16
16/* can be used to add custom fields to all watchers */ 17/* can be used to add custom fields to all watchers */
17#ifndef EV_COMMON 18#ifndef EV_COMMON
18# define EV_COMMON void *data 19# define EV_COMMON void *data
20#endif
21#ifndef EV_PROTOTYPES
22# define EV_PROTOTYPES 1
19#endif 23#endif
20 24
21/* 25/*
22 * struct member types: 26 * struct member types:
23 * private: you can look at them, but not change them, and they might not mean anything to you. 27 * private: you can look at them, but not change them, and they might not mean anything to you.
37 struct type *next /* private */ 41 struct type *next /* private */
38 42
39#define EV_WATCHER_TIME(type) \ 43#define EV_WATCHER_TIME(type) \
40 EV_WATCHER (type); \ 44 EV_WATCHER (type); \
41 ev_tstamp at /* private */ 45 ev_tstamp at /* private */
46
47/* base class, nothing to see here unless you subclass */
48struct ev_watcher {
49 EV_WATCHER (ev_watcher);
50};
51
52/* base class, nothing to see here unless you subclass */
53struct ev_watcher_list {
54 EV_WATCHER_LIST (ev_watcher_list);
55};
56
57/* base class, nothing to see here unless you subclass */
58struct ev_watcher_time {
59 EV_WATCHER_TIME (ev_watcher_time);
60};
42 61
43/* invoked after a specific time, repeatable (based on monotonic clock) */ 62/* invoked after a specific time, repeatable (based on monotonic clock) */
44struct ev_timer 63struct ev_timer
45{ 64{
46 EV_WATCHER_TIME (ev_timer); 65 EV_WATCHER_TIME (ev_timer);
86}; 105};
87 106
88#define EVMETHOD_NONE 0 107#define EVMETHOD_NONE 0
89#define EVMETHOD_SELECT 1 108#define EVMETHOD_SELECT 1
90#define EVMETHOD_EPOLL 2 109#define EVMETHOD_EPOLL 2
110#if EV_PROTOTYPES
111extern int ev_method;
91int ev_init (int flags); /* returns ev_method */ 112int ev_init (int flags); /* returns ev_method */
92extern int ev_method;
93 113
94/* these three calls are suitable for plugging into pthread_atfork */ 114/* these three calls are suitable for plugging into pthread_atfork */
95void ev_prefork (void); 115void ev_prefork (void);
96void ev_postfork_parent (void); 116void ev_postfork_parent (void);
97void ev_postfork_child (void); 117void ev_postfork_child (void);
98 118
99extern ev_tstamp ev_now; /* time w.r.t. timers and the eventloop, updated after each poll */ 119extern ev_tstamp ev_now; /* time w.r.t. timers and the eventloop, updated after each poll */
100ev_tstamp ev_time (void); 120ev_tstamp ev_time (void);
121#endif
101 122
102#define EVLOOP_NONBLOCK 1 /* do not block/wait */ 123#define EVLOOP_NONBLOCK 1 /* do not block/wait */
103#define EVLOOP_ONESHOT 2 /* block *once* only */ 124#define EVLOOP_ONESHOT 2 /* block *once* only */
125#if EV_PROTOTYPES
104void ev_loop (int flags); 126void ev_loop (int flags);
105extern int ev_loop_done; /* set to 1 to break out of event loop */ 127extern int ev_loop_done; /* set to 1 to break out of event loop, set to 2 to break out of all event loops */
128
129/* convinience function, wait for a single event, without registering an event watcher */
130/* if timeout is < 0, do wait indefinitely */
131void ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg);
132#endif
106 133
107/* these may evaluate ev multiple times, and the other arguments at most once */ 134/* these may evaluate ev multiple times, and the other arguments at most once */
108/* either use evw_init + evXXX_set, or the evXXX_init macro, below, to first initialise a watcher */ 135/* either use evw_init + evXXX_set, or the evXXX_init macro, below, to first initialise a watcher */
109#define evw_init(ev,cb_) do { (ev)->active = 0; (ev)->cb = (cb_); } while (0) 136#define evw_init(ev,cb_) do { (ev)->active = 0; (ev)->pending = 0; (ev)->cb = (cb_); } while (0)
110 137
111#define evio_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 138#define evio_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
112#define evtimer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) 139#define evtimer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0)
113#define evperiodic_set(ev,at_,interval_) do { (ev)->at = (at_); (ev)->interval = (interval_); } while (0) 140#define evperiodic_set(ev,at_,interval_) do { (ev)->at = (at_); (ev)->interval = (interval_); } while (0)
114#define evsignal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) 141#define evsignal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
115#define evcheck_set(ev) /* nop, yes this is a serious in-joke */ 142#define evcheck_set(ev) /* nop, yes, this is a serious in-joke */
116#define evidle_set(ev) /* nop, yes this is a serious in-joke */ 143#define evidle_set(ev) /* nop, yes, this is a serious in-joke */
117 144
118#define evio_init(ev,cb,fd,events) do { evw_init ((ev), (cb)); evio_set ((ev),(fd),(events)); } while (0) 145#define evio_init(ev,cb,fd,events) do { evw_init ((ev), (cb)); evio_set ((ev),(fd),(events)); } while (0)
119#define evtimer_init(ev,cb,after,repeat) do { evw_init ((ev), (cb)); evtimer_set ((ev),(after),(repeat)); } while (0) 146#define evtimer_init(ev,cb,after,repeat) do { evw_init ((ev), (cb)); evtimer_set ((ev),(after),(repeat)); } while (0)
120#define evperiodic_init(ev,cb,at,interval) do { evw_init ((ev), (cb)); evperiodic_set ((ev),(at),(interval)); } while (0) 147#define evperiodic_init(ev,cb,at,interval) do { evw_init ((ev), (cb)); evperiodic_set ((ev),(at),(interval)); } while (0)
121#define evsignal_init(ev,cb,signum) do { evw_init ((ev), (cb)); evsignal_set ((ev), (signum)); } while (0) 148#define evsignal_init(ev,cb,signum) do { evw_init ((ev), (cb)); evsignal_set ((ev), (signum)); } while (0)
124 151
125#define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ 152#define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */
126 153
127/* stopping (enabling, adding) a watcher does nothing if it is already running */ 154/* stopping (enabling, adding) a watcher does nothing if it is already running */
128/* stopping (disabling, deleting) a watcher does nothing unless its already running */ 155/* stopping (disabling, deleting) a watcher does nothing unless its already running */
156#if EV_PROTOTYPES
129void evio_start (struct ev_io *w); 157void evio_start (struct ev_io *w);
130void evio_stop (struct ev_io *w); 158void evio_stop (struct ev_io *w);
131 159
132void evtimer_start (struct ev_timer *w); 160void evtimer_start (struct ev_timer *w);
133void evtimer_stop (struct ev_timer *w); 161void evtimer_stop (struct ev_timer *w);
162void evtimer_again (struct ev_timer *w); /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */
134 163
135void evperiodic_start (struct ev_periodic *w); 164void evperiodic_start (struct ev_periodic *w);
136void evperiodic_stop (struct ev_periodic *w); 165void evperiodic_stop (struct ev_periodic *w);
137 166
138void evsignal_start (struct ev_signal *w); 167void evsignal_start (struct ev_signal *w);
141void evidle_start (struct ev_idle *w); 170void evidle_start (struct ev_idle *w);
142void evidle_stop (struct ev_idle *w); 171void evidle_stop (struct ev_idle *w);
143 172
144void evcheck_start (struct ev_check *w); 173void evcheck_start (struct ev_check *w);
145void evcheck_stop (struct ev_check *w); 174void evcheck_stop (struct ev_check *w);
175#endif
146 176
147#endif 177#endif
148 178

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines