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

Comparing libev/ev.h (file contents):
Revision 1.70 by root, Tue Nov 27 08:11:52 2007 UTC vs.
Revision 1.73 by root, Tue Nov 27 19:41:52 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;
211 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ 218 int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */
212} ev_child; 219} ev_child;
213 220
214#if EV_STAT_ENABLE 221#if EV_STAT_ENABLE
215/* st_nlink = 0 means missing file or other error */ 222/* st_nlink = 0 means missing file or other error */
223#ifdef _WIN32
224typedef struct _stati64 ev_statdata;
225#else
216typedef struct stat ev_statdata; 226typedef struct stat ev_statdata;
227#endif
217 228
218/* invoked each time the stat data changes for a given path */ 229/* invoked each time the stat data changes for a given path */
219/* revent EV_STAT */ 230/* revent EV_STAT */
220typedef struct ev_stat 231typedef struct ev_stat
221{ 232{
249typedef struct ev_check 260typedef struct ev_check
250{ 261{
251 EV_WATCHER (ev_check) 262 EV_WATCHER (ev_check)
252} ev_check; 263} ev_check;
253 264
265#if EV_FORK_ENABLE
266/* the callback gets invoked before check in the child process when a fork was detected */
267typedef struct ev_fork
268{
269 EV_WATCHER (ev_fork)
270} ev_fork;
271#endif
272
254#if EV_EMBED_ENABLE 273#if EV_EMBED_ENABLE
255/* used to embed an event loop inside another */ 274/* used to embed an event loop inside another */
256/* the callback gets invoked when the event loop has handled events, and can be 0 */ 275/* the callback gets invoked when the event loop has handled events, and can be 0 */
257typedef struct ev_embed 276typedef struct ev_embed
258{ 277{
270 struct ev_watcher_list wl; 289 struct ev_watcher_list wl;
271 290
272 struct ev_io io; 291 struct ev_io io;
273 struct ev_timer timer; 292 struct ev_timer timer;
274 struct ev_periodic periodic; 293 struct ev_periodic periodic;
294 struct ev_signal signal;
275 struct ev_child child; 295 struct ev_child child;
276#if EV_STAT_ENABLE 296#if EV_STAT_ENABLE
277 struct ev_stat stat; 297 struct ev_stat stat;
278#endif 298#endif
279 struct ev_idle idle; 299 struct ev_idle idle;
280 struct ev_prepare prepare; 300 struct ev_prepare prepare;
281 struct ev_check check; 301 struct ev_check check;
282 struct ev_signal signal; 302#if EV_FORK_ENABLE
303 struct ev_fork fork;
304#endif
283#if EV_EMBED_ENABLE 305#if EV_EMBED_ENABLE
284 struct ev_embed embed; 306 struct ev_embed embed;
285#endif 307#endif
286}; 308};
287 309
312 * It is used to allocate and free memory. 334 * It is used to allocate and free memory.
313 * If it returns zero when memory needs to be allocated, the library might abort 335 * If it returns zero when memory needs to be allocated, the library might abort
314 * or take some potentially destructive action. 336 * or take some potentially destructive action.
315 * The default is your system realloc function. 337 * The default is your system realloc function.
316 */ 338 */
317void ev_set_allocator (void *(*cb)(void *ptr, long size)); 339void ev_set_allocator (void *(*cb)(void *ptr, size_t size));
318 340
319/* set the callback function to call on a 341/* set the callback function to call on a
320 * retryable syscall error 342 * retryable syscall error
321 * (such as failed select, poll, epoll_wait) 343 * (such as failed select, poll, epoll_wait)
322 */ 344 */
407#define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); } while (0) 429#define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); } while (0)
408#define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ 430#define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */
409#define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ 431#define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */
410#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ 432#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */
411#define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0) 433#define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0)
434#define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */
412 435
413#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0) 436#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) 437#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) 438#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) 439#define ev_signal_init(ev,cb,signum) do { ev_init ((ev), (cb)); ev_signal_set ((ev), (signum)); } while (0)
418#define ev_stat_init(ev,cb,path,interval) do { ev_init ((ev), (cb)); ev_path_set ((ev),(path),(interval)); } while (0) 441#define ev_stat_init(ev,cb,path,interval) do { ev_init ((ev), (cb)); ev_path_set ((ev),(path),(interval)); } while (0)
419#define ev_idle_init(ev,cb) do { ev_init ((ev), (cb)); ev_idle_set ((ev)); } while (0) 442#define ev_idle_init(ev,cb) do { ev_init ((ev), (cb)); ev_idle_set ((ev)); } while (0)
420#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) 443#define ev_prepare_init(ev,cb) do { ev_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0)
421#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0) 444#define ev_check_init(ev,cb) do { ev_init ((ev), (cb)); ev_check_set ((ev)); } while (0)
422#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0) 445#define ev_embed_init(ev,cb,loop) do { ev_init ((ev), (cb)); ev_embed_set ((ev),(loop)); } while (0)
446#define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0)
423 447
424#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ 448#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 */ 449#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
426 450
427#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ 451#define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */
476void ev_prepare_start (EV_P_ ev_prepare *w); 500void ev_prepare_start (EV_P_ ev_prepare *w);
477void ev_prepare_stop (EV_P_ ev_prepare *w); 501void ev_prepare_stop (EV_P_ ev_prepare *w);
478 502
479void ev_check_start (EV_P_ ev_check *w); 503void ev_check_start (EV_P_ ev_check *w);
480void ev_check_stop (EV_P_ ev_check *w); 504void ev_check_stop (EV_P_ ev_check *w);
505
506# if EV_FORK_ENABLE
507void ev_fork_start (EV_P_ ev_fork *w);
508void ev_fork_stop (EV_P_ ev_fork *w);
509# endif
481 510
482# if EV_EMBED_ENABLE 511# if EV_EMBED_ENABLE
483/* only supported when loop to be embedded is in fact embeddable */ 512/* only supported when loop to be embedded is in fact embeddable */
484void ev_embed_start (EV_P_ ev_embed *w); 513void ev_embed_start (EV_P_ ev_embed *w);
485void ev_embed_stop (EV_P_ ev_embed *w); 514void ev_embed_stop (EV_P_ ev_embed *w);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines