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

Comparing libev/ev.h (file contents):
Revision 1.50 by root, Sun Nov 11 01:07:35 2007 UTC vs.
Revision 1.54 by root, Mon Nov 12 05:53:55 2007 UTC

71#endif 71#endif
72 72
73/* eventmask, revents, events... */ 73/* eventmask, revents, events... */
74#define EV_UNDEF -1 /* guaranteed to be invalid */ 74#define EV_UNDEF -1 /* guaranteed to be invalid */
75#define EV_NONE 0x00 75#define EV_NONE 0x00
76#define EV_READ 0x01 76#define EV_READ 0x01 /* io only */
77#define EV_WRITE 0x02 77#define EV_WRITE 0x02 /* io only */
78#define EV_TIMEOUT 0x000100 78#define EV_TIMEOUT 0x000100 /* timer only */
79#define EV_PERIODIC 0x000200 79#define EV_PERIODIC 0x000200 /* periodic timer only */
80#define EV_SIGNAL 0x000400 80#define EV_SIGNAL 0x000400 /* signal only */
81#define EV_IDLE 0x000800 81#define EV_IDLE 0x000800 /* idle only */
82#define EV_CHECK 0x001000 82#define EV_CHECK 0x001000 /* check only */
83#define EV_PREPARE 0x002000 83#define EV_PREPARE 0x002000 /* prepare only */
84#define EV_CHILD 0x004000 84#define EV_CHILD 0x004000 /* child/pid only */
85#define EV_ERROR 0x800000 /* sent when an error occurs */ 85#define EV_ERROR 0x800000 /* sent when an error occurs */
86 86
87/* can be used to add custom fields to all watchers */ 87/* can be used to add custom fields to all watchers, while losing binary compatibility */
88#ifndef EV_COMMON 88#ifndef EV_COMMON
89# define EV_COMMON void *data 89# define EV_COMMON void *data;
90#endif 90#endif
91#ifndef EV_PROTOTYPES 91#ifndef EV_PROTOTYPES
92# define EV_PROTOTYPES 1 92# define EV_PROTOTYPES 1
93#endif 93#endif
94 94
112/* shared by all watchers */ 112/* shared by all watchers */
113#define EV_WATCHER(type) \ 113#define EV_WATCHER(type) \
114 int active; /* private */ \ 114 int active; /* private */ \
115 int pending; /* private */ \ 115 int pending; /* private */ \
116 int priority; /* private */ \ 116 int priority; /* private */ \
117 EV_COMMON; /* rw */ \ 117 EV_COMMON /* rw */ \
118 EV_CB_DECLARE (type) /* private */ 118 EV_CB_DECLARE (type) /* private */
119 119
120#define EV_WATCHER_LIST(type) \ 120#define EV_WATCHER_LIST(type) \
121 EV_WATCHER (type); \ 121 EV_WATCHER (type) \
122 struct ev_watcher_list *next /* private */ 122 struct ev_watcher_list *next; /* private */
123 123
124#define EV_WATCHER_TIME(type) \ 124#define EV_WATCHER_TIME(type) \
125 EV_WATCHER (type); \ 125 EV_WATCHER (type) \
126 ev_tstamp at /* private */ 126 ev_tstamp at; /* private */
127 127
128/* base class, nothing to see here unless you subclass */ 128/* base class, nothing to see here unless you subclass */
129struct ev_watcher 129struct ev_watcher
130{ 130{
131 EV_WATCHER (ev_watcher); 131 EV_WATCHER (ev_watcher)
132}; 132};
133 133
134/* base class, nothing to see here unless you subclass */ 134/* base class, nothing to see here unless you subclass */
135struct ev_watcher_list 135struct ev_watcher_list
136{ 136{
137 EV_WATCHER_LIST (ev_watcher_list); 137 EV_WATCHER_LIST (ev_watcher_list)
138}; 138};
139 139
140/* base class, nothing to see here unless you subclass */ 140/* base class, nothing to see here unless you subclass */
141struct ev_watcher_time 141struct ev_watcher_time
142{ 142{
143 EV_WATCHER_TIME (ev_watcher_time); 143 EV_WATCHER_TIME (ev_watcher_time)
144}; 144};
145 145
146/* invoked after a specific time, repeatable (based on monotonic clock) */ 146/* invoked after a specific time, repeatable (based on monotonic clock) */
147/* revent EV_TIMEOUT */ 147/* revent EV_TIMEOUT */
148struct ev_timer 148struct ev_timer
149{ 149{
150 EV_WATCHER_TIME (ev_timer); 150 EV_WATCHER_TIME (ev_timer)
151 151
152 ev_tstamp repeat; /* rw */ 152 ev_tstamp repeat; /* rw */
153}; 153};
154 154
155/* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */ 155/* invoked at some specific time, possibly repeating at regular intervals (based on UTC) */
156/* revent EV_PERIODIC */ 156/* revent EV_PERIODIC */
157struct ev_periodic 157struct ev_periodic
158{ 158{
159 EV_WATCHER_TIME (ev_periodic); 159 EV_WATCHER_TIME (ev_periodic)
160 160
161 ev_tstamp interval; /* rw */ 161 ev_tstamp interval; /* rw */
162 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ 162 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */
163}; 163};
164 164
165/* invoked when fd is either EV_READable or EV_WRITEable */ 165/* invoked when fd is either EV_READable or EV_WRITEable */
166/* revent EV_READ, EV_WRITE */ 166/* revent EV_READ, EV_WRITE */
167struct ev_io 167struct ev_io
168{ 168{
169 EV_WATCHER_LIST (ev_io); 169 EV_WATCHER_LIST (ev_io)
170 170
171 int fd; /* ro */ 171 int fd; /* ro */
172 int events; /* ro */ 172 int events; /* ro */
173}; 173};
174 174
175/* invoked when the given signal has been received */ 175/* invoked when the given signal has been received */
176/* revent EV_SIGNAL */ 176/* revent EV_SIGNAL */
177struct ev_signal 177struct ev_signal
178{ 178{
179 EV_WATCHER_LIST (ev_signal); 179 EV_WATCHER_LIST (ev_signal)
180 180
181 int signum; /* ro */ 181 int signum; /* ro */
182}; 182};
183 183
184/* invoked when the nothing else needs to be done, keeps the process from blocking */ 184/* invoked when the nothing else needs to be done, keeps the process from blocking */
185/* revent EV_IDLE */ 185/* revent EV_IDLE */
186struct ev_idle 186struct ev_idle
187{ 187{
188 EV_WATCHER (ev_idle); 188 EV_WATCHER (ev_idle)
189}; 189};
190 190
191/* invoked for each run of the mainloop, just before the blocking call */ 191/* invoked for each run of the mainloop, just before the blocking call */
192/* you can still change events in any way you like */ 192/* you can still change events in any way you like */
193/* revent EV_PREPARE */ 193/* revent EV_PREPARE */
194struct ev_prepare 194struct ev_prepare
195{ 195{
196 EV_WATCHER (ev_prepare); 196 EV_WATCHER (ev_prepare)
197}; 197};
198 198
199/* invoked for each run of the mainloop, just after the blocking call */ 199/* invoked for each run of the mainloop, just after the blocking call */
200/* revent EV_CHECK */ 200/* revent EV_CHECK */
201struct ev_check 201struct ev_check
202{ 202{
203 EV_WATCHER (ev_check); 203 EV_WATCHER (ev_check)
204}; 204};
205 205
206/* invoked when sigchld is received and waitpid indicates the givne pid */ 206/* invoked when sigchld is received and waitpid indicates the givne pid */
207/* revent EV_CHILD */ 207/* revent EV_CHILD */
208/* does not support priorities */ 208/* does not support priorities */
209struct ev_child 209struct ev_child
210{ 210{
211 EV_WATCHER_LIST (ev_child); 211 EV_WATCHER_LIST (ev_child)
212 212
213 int pid; /* ro */ 213 int pid; /* ro */
214 int rpid; /* rw, holds the received pid */ 214 int rpid; /* rw, holds the received pid */
215 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ 215 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */
216}; 216};
229 struct ev_check check; 229 struct ev_check check;
230 struct ev_signal signal; 230 struct ev_signal signal;
231 struct ev_child child; 231 struct ev_child child;
232}; 232};
233 233
234/* bits for ev_default_loop and ev_loop_new */
235/* the default */
236#define EVMETHOD_AUTO 0x00000000 /* not quite a mask */
237
238/* method bits to be ored together */
239#define EVMETHOD_SELECT 0x00000001 /* about anywhere */
240#define EVMETHOD_POLL 0x00000002 /* !win */
241#define EVMETHOD_EPOLL 0x00000004 /* linux */
242#define EVMETHOD_KQUEUE 0x00000008 /* bsd */
243#define EVMETHOD_DEVPOLL 0x00000010 /* solaris 8 */ /* NYI */
244#define EVMETHOD_PORT 0x00000020 /* solaris 10 */ /* NYI */
245
246/* flag bits */
234#define EVMETHOD_AUTO 0 /* consults environment */ 247#define EVMETHOD_NOENV 0x01000000 /* do NOT consult environment */
235#define EVMETHOD_SELECT 1
236#define EVMETHOD_POLL 2
237#define EVMETHOD_EPOLL 4
238#define EVMETHOD_KQUEUE 8
239#define EVMETHOD_DEVPOLL 16 /* NYI */
240#define EVMETHOD_PORT 32 /* NYI */
241#define EVMETHOD_WIN32 64 /* NYI */
242#define EVMETHOD_ANY ~0 /* any method, do not consult env */
243 248
244#if EV_PROTOTYPES 249#if EV_PROTOTYPES
245int ev_version_major (void); 250int ev_version_major (void);
246int ev_version_minor (void); 251int ev_version_minor (void);
247 252
262void ev_set_syserr_cb (void (*cb)(const char *msg)); 267void ev_set_syserr_cb (void (*cb)(const char *msg));
263 268
264# if EV_MULTIPLICITY 269# if EV_MULTIPLICITY
265/* the default loop is the only one that handles signals and child watchers */ 270/* the default loop is the only one that handles signals and child watchers */
266/* you can call this as often as you like */ 271/* you can call this as often as you like */
267struct ev_loop *ev_default_loop (int methods); /* returns default loop */ 272struct ev_loop *ev_default_loop (unsigned int flags); /* returns default loop */
268 273
269/* create and destroy alternative loops that don't handle signals */ 274/* create and destroy alternative loops that don't handle signals */
270struct ev_loop *ev_loop_new (int methods); 275struct ev_loop *ev_loop_new (unsigned int flags);
271void ev_loop_destroy (EV_P); 276void ev_loop_destroy (EV_P);
272void ev_loop_fork (EV_P); 277void ev_loop_fork (EV_P);
273 278
274ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ 279ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */
275 280
276# else 281# else
277 282
278int ev_default_loop (int methods); /* returns true when successful */ 283int ev_default_loop (unsigned int flags); /* returns true when successful */
279 284
280static ev_tstamp 285static ev_tstamp
281ev_now () 286ev_now (void)
282{ 287{
283 extern ev_tstamp ev_rt_now; 288 extern ev_tstamp ev_rt_now;
284 289
285 return ev_rt_now; 290 return ev_rt_now;
286} 291}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines