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

Comparing libev/ev.h (file contents):
Revision 1.69 by root, Mon Nov 26 19:49:36 2007 UTC vs.
Revision 1.74 by root, Wed Nov 28 11:15:55 2007 UTC

54 54
55#ifndef EV_STAT_ENABLE 55#ifndef EV_STAT_ENABLE
56# define EV_STAT_ENABLE 1 56# define EV_STAT_ENABLE 1
57#endif 57#endif
58 58
59#ifndef EV_FORK_ENABLE
60# define EV_FORK_ENABLE 1
61#endif
62
59#ifndef EV_EMBED_ENABLE 63#ifndef EV_EMBED_ENABLE
60# define EV_EMBED_ENABLE 1 64# define EV_EMBED_ENABLE 1
61#endif 65#endif
62 66
63/*****************************************************************************/ 67/*****************************************************************************/
68
69#include <stddef.h> /* for size_t */
64 70
65#if EV_STAT_ENABLE 71#if EV_STAT_ENABLE
66# include <sys/stat.h> 72# include <sys/stat.h>
67#endif 73#endif
68 74
71struct ev_loop; 77struct ev_loop;
72# define EV_P struct ev_loop *loop 78# define EV_P struct ev_loop *loop
73# define EV_P_ EV_P, 79# define EV_P_ EV_P,
74# define EV_A loop 80# define EV_A loop
75# define EV_A_ EV_A, 81# define EV_A_ EV_A,
76# define EV_DEFAULT_A ev_default_loop (0) 82# define EV_DEFAULT ev_default_loop (0)
77# define EV_DEFAULT_A_ EV_DEFAULT_A, 83# define EV_DEFAULT_ EV_DEFAULT,
78#else 84#else
79# define EV_P void 85# define EV_P void
80# define EV_P_ 86# define EV_P_
81# define EV_A 87# define EV_A
82# define EV_A_ 88# define EV_A_
89# define EV_DEFAULT
83# define EV_DEFAULT_A 90# define EV_DEFAULT_
84# define EV_DEFAULT_A_
85 91
86# undef EV_EMBED_ENABLE 92# undef EV_EMBED_ENABLE
87#endif 93#endif
88 94
89/* eventmask, revents, events... */ 95/* eventmask, revents, events... */
92#define EV_READ 0x01L /* ev_io detected read will not block */ 98#define EV_READ 0x01L /* ev_io detected read will not block */
93#define EV_WRITE 0x02L /* ev_io detected write will not block */ 99#define EV_WRITE 0x02L /* ev_io detected write will not block */
94#define EV_TIMEOUT 0x00000100L /* timer timed out */ 100#define EV_TIMEOUT 0x00000100L /* timer timed out */
95#define EV_PERIODIC 0x00000200L /* periodic timer timed out */ 101#define EV_PERIODIC 0x00000200L /* periodic timer timed out */
96#define EV_SIGNAL 0x00000400L /* signal was received */ 102#define EV_SIGNAL 0x00000400L /* signal was received */
97#define EV_IDLE 0x00000800L /* event loop is idling */
98#define EV_PREPARE 0x00001000L /* event loop about to poll */
99#define EV_CHECK 0x00002000L /* event loop finished poll */
100#define EV_CHILD 0x00004000L /* child/pid had status change */ 103#define EV_CHILD 0x00000800L /* child/pid had status change */
104#define EV_STAT 0x00001000L /* stat data changed */
105#define EV_IDLE 0x00002000L /* event loop is idling */
106#define EV_PREPARE 0x00004000L /* event loop about to poll */
107#define EV_CHECK 0x00008000L /* event loop finished poll */
101#define EV_EMBED 0x00008000L /* embedded event loop needs sweep */ 108#define EV_EMBED 0x00010000L /* embedded event loop needs sweep */
102#define EV_STAT 0x00010000L /* stat data changed */ 109#define EV_FORK 0x00020000L /* event loop resumed in child */
103#define EV_ERROR 0x80000000L /* sent when an error occurs */ 110#define EV_ERROR 0x80000000L /* sent when an error occurs */
104 111
105/* can be used to add custom fields to all watchers, while losing binary compatibility */ 112/* can be used to add custom fields to all watchers, while losing binary compatibility */
106#ifndef EV_COMMON 113#ifndef EV_COMMON
107# define EV_COMMON void *data; 114# define EV_COMMON void *data;
159typedef struct ev_watcher_time 166typedef struct ev_watcher_time
160{ 167{
161 EV_WATCHER_TIME (ev_watcher_time) 168 EV_WATCHER_TIME (ev_watcher_time)
162} ev_watcher_time; 169} ev_watcher_time;
163 170
171/* invoked when fd is either EV_READable or EV_WRITEable */
172/* revent EV_READ, EV_WRITE */
173typedef struct ev_io
174{
175 EV_WATCHER_LIST (ev_io)
176
177 int fd; /* ro */
178 int events; /* ro */
179} ev_io;
180
164/* invoked after a specific time, repeatable (based on monotonic clock) */ 181/* invoked after a specific time, repeatable (based on monotonic clock) */
165/* revent EV_TIMEOUT */ 182/* revent EV_TIMEOUT */
166typedef struct ev_timer 183typedef struct ev_timer
167{ 184{
168 EV_WATCHER_TIME (ev_timer) 185 EV_WATCHER_TIME (ev_timer)
178 195
179 ev_tstamp interval; /* rw */ 196 ev_tstamp interval; /* rw */
180 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ 197 ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */
181} ev_periodic; 198} ev_periodic;
182 199
183/* invoked when fd is either EV_READable or EV_WRITEable */
184/* revent EV_READ, EV_WRITE */
185typedef struct ev_io
186{
187 EV_WATCHER_LIST (ev_io)
188
189 int fd; /* ro */
190 int events; /* ro */
191} ev_io;
192
193/* invoked when the given signal has been received */ 200/* invoked when the given signal has been received */
194/* revent EV_SIGNAL */ 201/* revent EV_SIGNAL */
195typedef struct ev_signal 202typedef struct ev_signal
196{ 203{
197 EV_WATCHER_LIST (ev_signal) 204 EV_WATCHER_LIST (ev_signal)
198 205
199 int signum; /* ro */ 206 int signum; /* ro */
200} ev_signal; 207} ev_signal;
208
209/* invoked when sigchld is received and waitpid indicates the given pid */
210/* revent EV_CHILD */
211/* does not support priorities */
212typedef struct ev_child
213{
214 EV_WATCHER_LIST (ev_child)
215
216 int pid; /* ro */
217 int rpid; /* rw, holds the received pid */
218 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */
219} ev_child;
220
221#if EV_STAT_ENABLE
222/* st_nlink = 0 means missing file or other error */
223# ifdef _WIN32
224typedef struct _stati64 ev_statdata;
225# else
226typedef struct stat ev_statdata;
227# endif
228
229/* invoked each time the stat data changes for a given path */
230/* revent EV_STAT */
231typedef struct ev_stat
232{
233 EV_WATCHER_LIST (ev_stat)
234
235 ev_timer timer; /* private */
236 ev_tstamp interval; /* ro */
237 const char *path; /* ro */
238 ev_statdata prev; /* ro */
239 ev_statdata attr; /* ro */
240
241 int wd; /* wd for inotify, fd for kqueue */
242} ev_stat;
243#endif
201 244
202/* invoked when the nothing else needs to be done, keeps the process from blocking */ 245/* invoked when the nothing else needs to be done, keeps the process from blocking */
203/* revent EV_IDLE */ 246/* revent EV_IDLE */
204typedef struct ev_idle 247typedef struct ev_idle
205{ 248{
219typedef struct ev_check 262typedef struct ev_check
220{ 263{
221 EV_WATCHER (ev_check) 264 EV_WATCHER (ev_check)
222} ev_check; 265} ev_check;
223 266
224/* invoked when sigchld is received and waitpid indicates the given pid */ 267#if EV_FORK_ENABLE
225/* revent EV_CHILD */ 268/* the callback gets invoked before check in the child process when a fork was detected */
226/* does not support priorities */
227typedef struct ev_child 269typedef struct ev_fork
228{ 270{
229 EV_WATCHER_LIST (ev_child) 271 EV_WATCHER (ev_fork)
230 272} ev_fork;
231 int pid; /* ro */ 273#endif
232 int rpid; /* rw, holds the received pid */
233 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */
234} ev_child;
235 274
236#if EV_EMBED_ENABLE 275#if EV_EMBED_ENABLE
237/* used to embed an event loop inside another */ 276/* used to embed an event loop inside another */
238/* the callback gets invoked when the event loop has handled events, and can be 0 */ 277/* the callback gets invoked when the event loop has handled events, and can be 0 */
239typedef struct ev_embed 278typedef struct ev_embed
243 ev_io io; /* private */ 282 ev_io io; /* private */
244 struct ev_loop *loop; /* ro */ 283 struct ev_loop *loop; /* ro */
245} ev_embed; 284} ev_embed;
246#endif 285#endif
247 286
248#if EV_STAT_ENABLE
249/* st_nlink = 0 means missing file or other error */
250typedef struct stat ev_statdata;
251
252/* invoked each time the stat data changes for a given path */
253/* revent EV_STAT */
254typedef struct ev_stat
255{
256 EV_WATCHER (ev_stat)
257
258 ev_timer timer; /* private */
259 ev_tstamp interval; /* rw */
260 const char *path; /* ro */
261 ev_statdata prev; /* ro */
262 ev_statdata attr; /* ro */
263} ev_stat;
264#endif
265
266/* the presence of this union forces similar struct layout */ 287/* the presence of this union forces similar struct layout */
267union ev_any_watcher 288union ev_any_watcher
268{ 289{
269 struct ev_watcher w; 290 struct ev_watcher w;
270 struct ev_watcher_list wl; 291 struct ev_watcher_list wl;
271 292
272 struct ev_io io; 293 struct ev_io io;
273 struct ev_timer timer; 294 struct ev_timer timer;
274 struct ev_periodic periodic; 295 struct ev_periodic periodic;
296 struct ev_signal signal;
297 struct ev_child child;
298#if EV_STAT_ENABLE
299 struct ev_stat stat;
300#endif
275 struct ev_idle idle; 301 struct ev_idle idle;
276 struct ev_prepare prepare; 302 struct ev_prepare prepare;
277 struct ev_check check; 303 struct ev_check check;
278 struct ev_signal signal; 304#if EV_FORK_ENABLE
279 struct ev_child child; 305 struct ev_fork fork;
306#endif
280#if EV_EMBED_ENABLE 307#if EV_EMBED_ENABLE
281 struct ev_embed embed; 308 struct ev_embed embed;
282#endif
283#if EV_STAT_ENABLE
284 struct ev_stat stat;
285#endif 309#endif
286}; 310};
287 311
288/* bits for ev_default_loop and ev_loop_new */ 312/* bits for ev_default_loop and ev_loop_new */
289/* the default */ 313/* the default */
312 * It is used to allocate and free memory. 336 * It is used to allocate and free memory.
313 * If it returns zero when memory needs to be allocated, the library might abort 337 * If it returns zero when memory needs to be allocated, the library might abort
314 * or take some potentially destructive action. 338 * or take some potentially destructive action.
315 * The default is your system realloc function. 339 * The default is your system realloc function.
316 */ 340 */
317void ev_set_allocator (void *(*cb)(void *ptr, long size)); 341void ev_set_allocator (void *(*cb)(void *ptr, size_t size));
318 342
319/* set the callback function to call on a 343/* set the callback function to call on a
320 * retryable syscall error 344 * retryable syscall error
321 * (such as failed select, poll, epoll_wait) 345 * (such as failed select, poll, epoll_wait)
322 */ 346 */
401 425
402#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) 426#define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0)
403#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) 427#define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0)
404#define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0) 428#define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0)
405#define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) 429#define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0)
430#define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0)
431#define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); (ev)->wd = -2; } while (0)
406#define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ 432#define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */
407#define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ 433#define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */
408#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ 434#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */
409#define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0)
410#define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0) 435#define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0)
411#define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); } while (0) 436#define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */
412 437
413#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0) 438#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0)
414#define ev_timer_init(ev,cb,after,repeat) do { ev_init ((ev), (cb)); ev_timer_set ((ev),(after),(repeat)); } while (0) 439#define ev_timer_init(ev,cb,after,repeat) do { ev_init ((ev), (cb)); ev_timer_set ((ev),(after),(repeat)); } while (0)
415#define ev_periodic_init(ev,cb,at,ival,res) do { ev_init ((ev), (cb)); ev_periodic_set ((ev),(at),(ival),(res)); } while (0) 440#define ev_periodic_init(ev,cb,at,ival,res) do { ev_init ((ev), (cb)); ev_periodic_set ((ev),(at),(ival),(res)); } while (0)
416#define ev_signal_init(ev,cb,signum) do { ev_init ((ev), (cb)); ev_signal_set ((ev), (signum)); } while (0) 441#define ev_signal_init(ev,cb,signum) do { ev_init ((ev), (cb)); ev_signal_set ((ev), (signum)); } while (0)
442#define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0)
443#define ev_stat_init(ev,cb,path,interval) do { ev_init ((ev), (cb)); ev_path_set ((ev),(path),(interval)); } while (0)
417#define ev_idle_init(ev,cb) do { ev_init ((ev), (cb)); ev_idle_set ((ev)); } while (0) 444#define ev_idle_init(ev,cb) do { ev_init ((ev), (cb)); ev_idle_set ((ev)); } while (0)
418#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) 445#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0)
419#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) 446#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0)
420#define ev_child_init(ev,cb,pid) do { ev_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0)
421#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0) 447#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0)
422#define ev_stat_init(ev,cb,path,interval) do { ev_init ((ev), (cb)); ev_path_set ((ev),(path),(interval)); } while (0) 448#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0)
423 449
424#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ 450#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
425#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ 451#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
426 452
427#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ 453#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */
454void ev_periodic_start (EV_P_ ev_periodic *w); 480void ev_periodic_start (EV_P_ ev_periodic *w);
455void ev_periodic_stop (EV_P_ ev_periodic *w); 481void ev_periodic_stop (EV_P_ ev_periodic *w);
456void ev_periodic_again (EV_P_ ev_periodic *w); 482void ev_periodic_again (EV_P_ ev_periodic *w);
457#endif 483#endif
458 484
459void ev_idle_start (EV_P_ ev_idle *w);
460void ev_idle_stop (EV_P_ ev_idle *w);
461
462void ev_prepare_start (EV_P_ ev_prepare *w);
463void ev_prepare_stop (EV_P_ ev_prepare *w);
464
465void ev_check_start (EV_P_ ev_check *w);
466void ev_check_stop (EV_P_ ev_check *w);
467
468/* only supported in the default loop */ 485/* only supported in the default loop */
469void ev_signal_start (EV_P_ ev_signal *w); 486void ev_signal_start (EV_P_ ev_signal *w);
470void ev_signal_stop (EV_P_ ev_signal *w); 487void ev_signal_stop (EV_P_ ev_signal *w);
471 488
472/* only supported in the default loop */ 489/* only supported in the default loop */
473void ev_child_start (EV_P_ ev_child *w); 490void ev_child_start (EV_P_ ev_child *w);
474void ev_child_stop (EV_P_ ev_child *w); 491void ev_child_stop (EV_P_ ev_child *w);
492
493# if EV_STAT_ENABLE
494void ev_stat_start (EV_P_ ev_stat *w);
495void ev_stat_stop (EV_P_ ev_stat *w);
496void ev_stat_stat (EV_P_ ev_stat *w);
497# endif
498
499void ev_idle_start (EV_P_ ev_idle *w);
500void ev_idle_stop (EV_P_ ev_idle *w);
501
502void ev_prepare_start (EV_P_ ev_prepare *w);
503void ev_prepare_stop (EV_P_ ev_prepare *w);
504
505void ev_check_start (EV_P_ ev_check *w);
506void ev_check_stop (EV_P_ ev_check *w);
507
508# if EV_FORK_ENABLE
509void ev_fork_start (EV_P_ ev_fork *w);
510void ev_fork_stop (EV_P_ ev_fork *w);
511# endif
475 512
476# if EV_EMBED_ENABLE 513# if EV_EMBED_ENABLE
477/* only supported when loop to be embedded is in fact embeddable */ 514/* only supported when loop to be embedded is in fact embeddable */
478void ev_embed_start (EV_P_ ev_embed *w); 515void ev_embed_start (EV_P_ ev_embed *w);
479void ev_embed_stop (EV_P_ ev_embed *w); 516void ev_embed_stop (EV_P_ ev_embed *w);
480void ev_embed_sweep (EV_P_ ev_embed *w); 517void ev_embed_sweep (EV_P_ ev_embed *w);
481# endif 518# endif
482 519
483# if EV_STAT_ENABLE
484void ev_stat_start (EV_P_ ev_stat *w);
485void ev_stat_stop (EV_P_ ev_stat *w);
486void ev_stat_stat (EV_P_ ev_stat *w);
487# endif
488
489#endif 520#endif
490 521
491#ifdef __cplusplus 522#ifdef __cplusplus
492} 523}
493#endif 524#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines