--- cvsroot/EV/EV.xs 2009/04/15 17:49:26 1.121 +++ cvsroot/EV/EV.xs 2009/07/14 00:09:59 1.126 @@ -2,12 +2,12 @@ #include "perl.h" #include "XSUB.h" -/*#include */ - /* fix perl api breakage */ #undef signal #undef sigaction +#include "schmorp.h" + #define EV_PROTOTYPES 1 #define EV_USE_NANOSLEEP EV_USE_MONOTONIC #define EV_H @@ -26,25 +26,6 @@ # include #endif -/* 5.10.0 */ -#ifndef SvREFCNT_inc_NN -# define SvREFCNT_inc_NN(sv) SvREFCNT_inc (sv) -#endif - -/* 5.6.x */ -#ifndef SvRV_set -# define SvRV_set(a,b) SvRV ((a)) = (b) -#endif - -#if __GNUC__ >= 3 -# define expect(expr,value) __builtin_expect ((expr),(value)) -#else -# define expect(expr,value) (expr) -#endif - -#define expect_false(expr) expect ((expr) != 0, 0) -#define expect_true(expr) expect ((expr) != 0, 1) - #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) #define WFLAG_KEEPALIVE 1 @@ -107,70 +88,15 @@ *stash_fork, *stash_async; -#ifndef SIG_SIZE -/* kudos to Slaven Rezic for the idea */ -static char sig_size [] = { SIG_NUM }; -# define SIG_SIZE (sizeof (sig_size) + 1) -#endif - -static Signal -sv_signum (SV *sig) -{ - Signal signum; - - SvGETMAGIC (sig); - - for (signum = 1; signum < SIG_SIZE; ++signum) - if (strEQ (SvPV_nolen (sig), PL_sig_name [signum])) - return signum; - - signum = SvIV (sig); - - if (signum > 0 && signum < SIG_SIZE) - return signum; - - return -1; -} - ///////////////////////////////////////////////////////////////////////////// // Event static void e_cb (EV_P_ ev_watcher *w, int revents); -static int -sv_fileno (SV *fh) -{ - SvGETMAGIC (fh); - - if (SvROK (fh)) - fh = SvRV (fh); - - if (SvTYPE (fh) == SVt_PVGV) - return PerlIO_fileno (IoIFP (sv_2io (fh))); - - if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) - return SvIV (fh); - - return -1; -} - -static SV * -e_get_cv (SV *cb_sv) -{ - HV *st; - GV *gvp; - CV *cv = sv_2cv (cb_sv, &st, &gvp, 0); - - if (!cv) - croak ("EV watcher callback must be a CODE reference"); - - return (SV *)cv; -} - static void * e_new (int size, SV *cb_sv, SV *loop) { - SV *cv = cb_sv ? e_get_cv (cb_sv) : 0; + SV *cv = cb_sv ? s_get_cv_croak (cb_sv) : 0; ev_watcher *w; SV *self = NEWSV (0, size); SvPOK_only (self); @@ -401,16 +327,28 @@ const_iv (EV_, UNDEF) const_iv (EV_, NONE) - const_iv (EV_, TIMEOUT) const_iv (EV_, READ) const_iv (EV_, WRITE) + const_iv (EV_, IO) + const_iv (EV_, TIMEOUT) + const_iv (EV_, TIMER) + const_iv (EV_, PERIODIC) const_iv (EV_, SIGNAL) + const_iv (EV_, CHILD) + const_iv (EV_, STAT) const_iv (EV_, IDLE) + const_iv (EV_, PREPARE) const_iv (EV_, CHECK) + const_iv (EV_, EMBED) + const_iv (EV_, FORK) + const_iv (EV_, ASYNC) + const_iv (EV_, CUSTOM) const_iv (EV_, ERROR) - const_iv (EV, LOOP_ONESHOT) 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) @@ -423,6 +361,9 @@ const_iv (EV, FLAG_AUTO) const_iv (EV, FLAG_NOENV) const_iv (EV, FLAG_FORKCHECK) + + const_iv (EV_, VERSION_MAJOR) + const_iv (EV_, VERSION_MINOR) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) @@ -450,8 +391,8 @@ /* the poor man's shared library emulator */ evapi.ver = EV_API_VERSION; evapi.rev = EV_API_REVISION; - evapi.sv_fileno = sv_fileno; - evapi.sv_signum = sv_signum; + evapi.sv_fileno = s_fileno; + evapi.sv_signum = s_signum; evapi.supported_backends = ev_supported_backends (); evapi.recommended_backends = ev_recommended_backends (); evapi.embeddable_backends = ev_embeddable_backends (); @@ -461,10 +402,18 @@ evapi.loop_destroy = ev_loop_destroy; evapi.loop_fork = ev_loop_fork; evapi.loop_count = ev_loop_count; + evapi.loop_depth = ev_loop_depth; + evapi.set_userdata = ev_set_userdata; + evapi.userdata = ev_userdata; evapi.now = ev_now; evapi.now_update = ev_now_update; + evapi.suspend = ev_suspend; + evapi.resume = ev_resume; evapi.backend = ev_backend; evapi.unloop = ev_unloop; + evapi.invoke_pending = ev_invoke_pending; + evapi.set_loop_release_cb = ev_set_loop_release_cb; + evapi.set_invoke_pending_cb= ev_set_invoke_pending_cb; evapi.ref = ev_ref; evapi.unref = ev_unref; evapi.loop = ev_loop; @@ -548,12 +497,24 @@ void ev_now_update () C_ARGS: evapi.default_loop +void ev_suspend () + C_ARGS: evapi.default_loop + +void ev_resume () + C_ARGS: evapi.default_loop + unsigned int ev_backend () C_ARGS: evapi.default_loop +void ev_loop_verify () + C_ARGS: evapi.default_loop + unsigned int ev_loop_count () C_ARGS: evapi.default_loop +unsigned int ev_loop_depth () + C_ARGS: evapi.default_loop + void ev_set_io_collect_interval (NV interval) C_ARGS: evapi.default_loop, interval @@ -572,7 +533,7 @@ void ev_feed_signal_event (SV *signal) CODE: { - Signal signum = sv_signum (signal); + Signal signum = s_signum (signal); CHECK_SIG (signal, signum); ev_feed_signal_event (evapi.default_loop, signum); @@ -583,7 +544,7 @@ io_ns = 1 CODE: { - int fd = sv_fileno (fh); + int fd = s_fileno (fh, events & EV_WRITE); CHECK_FD (fh, fd); RETVAL = e_new (sizeof (ev_io), cb, default_loop_sv); @@ -628,7 +589,7 @@ signal_ns = 1 CODE: { - Signal signum = sv_signum (signal); + Signal signum = s_signum (signal); CHECK_SIG (signal, signum); RETVAL = e_new (sizeof (ev_signal), cb, default_loop_sv); @@ -729,7 +690,7 @@ CODE: ev_once ( evapi.default_loop, - sv_fileno (fh), events, + s_fileno (fh, events & EV_WRITE), events, SvOK (timeout) ? SvNV (timeout) : -1., e_once_cb, newSVsv (cb) @@ -773,7 +734,7 @@ { if (items > 1) { - new_cb = e_get_cv (new_cb); + new_cb = s_get_cv_croak (new_cb); RETVAL = newRV_noinc (w->cb_sv); w->cb_sv = SvREFCNT_inc (new_cb); } @@ -853,7 +814,7 @@ void set (ev_io *w, SV *fh, int events) CODE: { - int fd = sv_fileno (fh); + int fd = s_fileno (fh, events & EV_WRITE); CHECK_FD (fh, fd); sv_setsv (w->fh, fh); @@ -865,7 +826,7 @@ { if (items > 1) { - int fd = sv_fileno (new_fh); + int fd = s_fileno (new_fh, w->events & EV_WRITE); CHECK_FD (new_fh, fd); RETVAL = w->fh; @@ -908,7 +869,7 @@ void set (ev_signal *w, SV *signal) CODE: { - Signal signum = sv_signum (signal); + Signal signum = s_signum (signal); CHECK_SIG (signal, signum); RESET (signal, w, (w, signum)); @@ -921,7 +882,7 @@ if (items > 1) { - Signal signum = sv_signum (new_signal); + Signal signum = s_signum (new_signal); CHECK_SIG (new_signal, signum); RESET (signal, w, (w, signum)); @@ -1266,6 +1227,10 @@ void ev_now_update (struct ev_loop *loop) +void ev_suspend (struct ev_loop *loop) + +void ev_resume (struct ev_loop *loop) + void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) @@ -1274,6 +1239,8 @@ unsigned int ev_loop_count (struct ev_loop *loop) +unsigned int ev_loop_depth (struct ev_loop *loop) + void ev_loop (struct ev_loop *loop, int flags = 0) void ev_unloop (struct ev_loop *loop, int how = 1) @@ -1285,7 +1252,7 @@ void ev_feed_signal_event (struct ev_loop *loop, SV *signal) CODE: { - Signal signum = sv_signum (signal); + Signal signum = s_signum (signal); CHECK_SIG (signal, signum); ev_feed_signal_event (loop, signum); @@ -1298,7 +1265,7 @@ io_ns = 1 CODE: { - int fd = sv_fileno (fh); + int fd = s_fileno (fh, events & EV_WRITE); CHECK_FD (fh, fd); RETVAL = e_new (sizeof (ev_io), cb, ST (0)); @@ -1345,7 +1312,7 @@ signal_ns = 1 CODE: { - Signal signum = sv_signum (signal); + Signal signum = s_signum (signal); CHECK_SIG (signal, signum); RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); @@ -1448,7 +1415,7 @@ CODE: ev_once ( loop, - sv_fileno (fh), events, + s_fileno (fh, events & EV_WRITE), events, SvOK (timeout) ? SvNV (timeout) : -1., e_once_cb, newSVsv (cb)