--- cvsroot/EV/EV.xs 2010/04/14 00:17:22 1.138 +++ cvsroot/EV/EV.xs 2010/10/28 04:59:35 1.147 @@ -31,7 +31,7 @@ /* due to bugs in OS X we have to use libev/ explicitly here */ #include "libev/ev.c" -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(_MINIX) # include #endif @@ -122,6 +122,7 @@ *stash_check, *stash_embed, *stash_fork, + *stash_cleanup, *stash_async; ///////////////////////////////////////////////////////////////////////////// @@ -342,6 +343,11 @@ #define CHECK_SIG(sv,num) if ((num) < 0) \ croak ("illegal signal number or name: %s", SvPV_nolen (sv)); +EV_INLINE default_fork (void) +{ + ev_loop_fork (EV_DEFAULT_UC); +} + ///////////////////////////////////////////////////////////////////////////// // XS interface functions @@ -366,7 +372,6 @@ const_iv (EV_, READ) const_iv (EV_, WRITE) const_iv (EV_, IO) - const_iv (EV_, TIMEOUT) /* deprecated */ const_iv (EV_, TIMER) const_iv (EV_, PERIODIC) const_iv (EV_, SIGNAL) @@ -377,17 +382,17 @@ const_iv (EV_, CHECK) const_iv (EV_, EMBED) const_iv (EV_, FORK) + const_iv (EV_, CLEANUP) const_iv (EV_, ASYNC) const_iv (EV_, CUSTOM) const_iv (EV_, ERROR) - const_iv (EV, LOOP_NONBLOCK) - const_iv (EV, LOOP_ONESHOT) - - const_iv (EV, UNLOOP_CANCEL) - const_iv (EV, UNLOOP_ONE) - const_iv (EV, UNLOOP_ALL) + const_iv (EV, RUN_NOWAIT) + const_iv (EV, RUN_ONCE) + const_iv (EV, BREAK_CANCEL) + const_iv (EV, BREAK_ONE) + const_iv (EV, BREAK_ALL) const_iv (EV, BACKEND_SELECT) const_iv (EV, BACKEND_POLL) const_iv (EV, BACKEND_EPOLL) @@ -399,11 +404,19 @@ const_iv (EV, FLAG_FORKCHECK) const_iv (EV, FLAG_SIGNALFD) const_iv (EV, FLAG_NOENV) - const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */ const_iv (EV, FLAG_NOINOTIFY) const_iv (EV_, VERSION_MAJOR) const_iv (EV_, VERSION_MINOR) +#if EV_COMPAT3 + const_iv (EV, FLAG_NOSIGFD) /* compatibility, always 0 */ + const_iv (EV_, TIMEOUT) + const_iv (EV, LOOP_NONBLOCK) + const_iv (EV, LOOP_ONESHOT) + const_iv (EV, UNLOOP_CANCEL) + const_iv (EV, UNLOOP_ONE) + const_iv (EV, UNLOOP_ALL) +#endif }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) @@ -422,6 +435,7 @@ stash_embed = gv_stashpv ("EV::Embed" , 1); stash_stat = gv_stashpv ("EV::Stat" , 1); stash_fork = gv_stashpv ("EV::Fork" , 1); + stash_cleanup = gv_stashpv ("EV::Cleanup" , 1); stash_async = gv_stashpv ("EV::Async" , 1); { @@ -450,7 +464,7 @@ evapi.suspend = ev_suspend; evapi.resume = ev_resume; evapi.backend = ev_backend; - evapi.unloop = ev_unloop; + evapi.break_ = ev_break; evapi.invoke_pending = ev_invoke_pending; evapi.pending_count = ev_pending_count; evapi.verify = ev_verify; @@ -458,7 +472,7 @@ evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; evapi.ref = ev_ref; evapi.unref = ev_unref; - evapi.loop = ev_loop; + evapi.run = ev_run; evapi.once = ev_once; evapi.io_start = ev_io_start; evapi.io_stop = ev_io_stop; @@ -476,8 +490,10 @@ evapi.prepare_stop = ev_prepare_stop; evapi.check_start = ev_check_start; evapi.check_stop = ev_check_stop; +#if EV_CHILD_ENABLE evapi.child_start = ev_child_start; evapi.child_stop = ev_child_stop; +#endif evapi.stat_start = ev_stat_start; evapi.stat_stop = ev_stat_stop; evapi.stat_stat = ev_stat_stat; @@ -486,6 +502,8 @@ evapi.embed_sweep = ev_embed_sweep; evapi.fork_start = ev_fork_start; evapi.fork_stop = ev_fork_stop; + evapi.cleanup_start = ev_cleanup_start; + evapi.cleanup_stop = ev_cleanup_stop; evapi.async_start = ev_async_start; evapi.async_stop = ev_async_stop; evapi.async_send = ev_async_send; @@ -495,8 +513,8 @@ sv_setiv (sv, (IV)&evapi); SvREADONLY_on (sv); } -#ifndef _WIN32 - pthread_atfork (0, 0, ev_default_fork); +#if !defined(_WIN32) && !defined(_MINIX) + pthread_atfork (0, 0, default_fork); #endif } @@ -520,7 +538,7 @@ void ev_default_destroy () CODE: - ev_default_destroy (); + ev_loop_destroy (EV_DEFAULT_UC); SvREFCNT_dec (default_loop_sv); default_loop_sv = 0; @@ -550,12 +568,18 @@ C_ARGS: evapi.default_loop void ev_verify () + ALIAS: + loop_verify = 1 C_ARGS: evapi.default_loop unsigned int ev_iteration () + ALIAS: + loop_count = 1 C_ARGS: evapi.default_loop unsigned int ev_depth () + ALIAS: + loop_depth = 1 C_ARGS: evapi.default_loop void ev_set_io_collect_interval (NV interval) @@ -564,10 +588,14 @@ void ev_set_timeout_collect_interval (NV interval) C_ARGS: evapi.default_loop, interval -void ev_loop (int flags = 0) +void ev_run (int flags = 0) + ALIAS: + loop = 1 C_ARGS: evapi.default_loop, flags -void ev_unloop (int how = EVUNLOOP_ONE) +void ev_break (int how = EVBREAK_ONE) + ALIAS: + unloop = 1 C_ARGS: evapi.default_loop, how void ev_feed_fd_event (int fd, int revents = EV_NONE) @@ -695,16 +723,31 @@ OUTPUT: RETVAL +ev_cleanup *cleanup (SV *cb) + ALIAS: + cleanup_ns = 1 + CODE: + RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv); + ev_cleanup_set (RETVAL); + if (!ix) START (cleanup, RETVAL); + OUTPUT: + RETVAL + ev_child *child (int pid, int trace, SV *cb) ALIAS: child_ns = 1 CODE: +#if EV_CHILD_ENABLE RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); ev_child_set (RETVAL, pid, trace); if (!ix) START (child, RETVAL); +#else + croak ("EV::child watchers not supported on this platform"); +#endif OUTPUT: RETVAL + ev_stat *stat (SV *path, NV interval, SV *cb) ALIAS: stat_ns = 1 @@ -1079,8 +1122,31 @@ STOP (fork, w); e_destroy (w); +MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_ + +void ev_cleanup_start (ev_cleanup *w) + CODE: + START (cleanup, w); + +void ev_cleanup_stop (ev_cleanup *w) + CODE: + STOP (cleanup, w); + +void DESTROY (ev_cleanup *w) + CODE: + STOP (cleanup, w); + e_destroy (w); + +int keepalive (ev_watcher *w, int new_value = 0) + CODE: + RETVAL = 0; + OUTPUT: + RETVAL + MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ +#if EV_CHILD_ENABLE + void ev_child_start (ev_child *w) CODE: START (child, w); @@ -1109,6 +1175,8 @@ OUTPUT: RETVAL +#endif + MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ void ev_stat_start (ev_stat *w) @@ -1275,13 +1343,13 @@ void DESTROY (struct ev_loop *loop) CODE: - if (loop != evapi.default_loop) /* global destruction sucks */ + /* 1. the default loop shouldn't be freed by destroying it'S pelr loop object */ + /* 2. not doing so helps avoid many global destruction bugs in perl, too */ + if (loop != evapi.default_loop) ev_loop_destroy (loop); void ev_loop_fork (struct ev_loop *loop) -void ev_verify (struct ev_loop *loop) - NV ev_now (struct ev_loop *loop) void ev_now_update (struct ev_loop *loop) @@ -1296,13 +1364,25 @@ unsigned int ev_backend (struct ev_loop *loop) +void ev_verify (struct ev_loop *loop) + ALIAS: + loop_verify = 1 + unsigned int ev_iteration (struct ev_loop *loop) + ALIAS: + loop_count = 1 unsigned int ev_depth (struct ev_loop *loop) + ALIAS: + loop_depth = 1 -void ev_loop (struct ev_loop *loop, int flags = 0) +void ev_run (struct ev_loop *loop, int flags = 0) + ALIAS: + loop = 1 -void ev_unloop (struct ev_loop *loop, int how = 1) +void ev_break (struct ev_loop *loop, int how = 1) + ALIAS: + unloop = 1 void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE) @@ -1423,13 +1503,27 @@ OUTPUT: RETVAL +ev_cleanup *cleanup (struct ev_loop *loop, SV *cb) + ALIAS: + cleanup_ns = 1 + CODE: + RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0)); + ev_cleanup_set (RETVAL); + if (!ix) START (cleanup, RETVAL); + OUTPUT: + RETVAL + ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) ALIAS: child_ns = 1 CODE: +#if EV_CHILD_ENABLE RETVAL = e_new (sizeof (ev_child), cb, ST (0)); ev_child_set (RETVAL, pid, trace); if (!ix) START (child, RETVAL); +#else + croak ("EV::child watchers not supported on this platform"); +#endif OUTPUT: RETVAL