--- cvsroot/EV/EV.xs 2007/11/08 17:24:00 1.61 +++ cvsroot/EV/EV.xs 2007/11/23 16:37:37 1.77 @@ -11,13 +11,17 @@ #undef signal #undef sigaction -#define EV_SELECT_USE_WIN32_HANDLES 0 -#define EV_SELECT_USE_FD_SET 0 +#define EV_SELECT_IS_WINSOCKET 0 +#ifdef _WIN32 +# define EV_SELECT_USE_FD_SET 0 +# define NFDBITS PERL_NFDBITS +# define fd_mask Perl_fd_mask +#endif /* due to bugs in OS X we have to use libev/ explicitly here */ #include "libev/ev.c" #include "event.c" -#ifndef WIN32 +#ifndef _WIN32 #define DNS_USE_GETTIMEOFDAY_FOR_ID 1 #if !defined (WIN32) && !defined(__CYGWIN__) # define HAVE_STRUCT_IN6_ADDR 1 @@ -25,10 +29,11 @@ #undef HAVE_STRTOK_R #undef strtok_r #define strtok_r fake_strtok_r +#include "evdns.h" #include "evdns.c" #endif -#ifndef WIN32 +#ifndef _WIN32 # include #endif @@ -86,7 +91,7 @@ if (SvTYPE (fh) == SVt_PVGV) return PerlIO_fileno (IoIFP (sv_2io (fh))); - if ((SvIV (fh) >= 0) && (SvIV (fh) < 0x7ffffff)) + if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL)) return SvIV (fh); return -1; @@ -102,7 +107,7 @@ w = (struct ev_watcher *)SvPVX (self); - ev_watcher_init (w, e_cb); + ev_init (w, e_cb); w->data = 0; w->fh = 0; @@ -139,13 +144,14 @@ return rv; } +static SV *sv_events_cache; + static void e_cb (struct ev_watcher *w, int revents) { dSP; I32 mark = SP - PL_stack_base; - SV *sv_self, *sv_events, *sv_status = 0; - static SV *sv_events_cache; + SV *sv_self, *sv_events; sv_self = newRV_inc (w->self); /* w->self MUST be blessed by now */ @@ -164,10 +170,8 @@ PUTBACK; call_sv (w->cb_sv, G_DISCARD | G_VOID | G_EVAL); - SP = PL_stack_base + mark; PUTBACK; SvREFCNT_dec (sv_self); - SvREFCNT_dec (sv_status); if (sv_events_cache) SvREFCNT_dec (sv_events); @@ -179,8 +183,49 @@ PUSHMARK (SP); PUTBACK; call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); - SP = PL_stack_base + mark; PUTBACK; } + + SP = PL_stack_base + mark; + PUTBACK; +} + +static void +e_once_cb (int revents, void *arg) +{ + dSP; + I32 mark = SP - PL_stack_base; + SV *sv_events; + + if (sv_events_cache) + { + sv_events = sv_events_cache; sv_events_cache = 0; + SvIV_set (sv_events, revents); + } + else + sv_events = newSViv (revents); + + PUSHMARK (SP); + XPUSHs (sv_events); + + PUTBACK; + call_sv ((SV *)arg, G_DISCARD | G_VOID | G_EVAL); + + SvREFCNT_dec ((SV *)arg); + + if (sv_events_cache) + SvREFCNT_dec (sv_events); + else + sv_events_cache = sv_events; + + if (SvTRUE (ERRSV)) + { + PUSHMARK (SP); + PUTBACK; + call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); + } + + SP = PL_stack_base + mark; + PUTBACK; } static ev_tstamp @@ -229,7 +274,7 @@ ///////////////////////////////////////////////////////////////////////////// // DNS -#ifndef WIN32 +#ifndef _WIN32 static void dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg) { @@ -317,15 +362,17 @@ const_iv (EV, LOOP_ONESHOT) const_iv (EV, LOOP_NONBLOCK) + const_iv (EV, UNLOOP_ONE) + const_iv (EV, UNLOOP_ALL) - const_iv (EV, METHOD_AUTO) - const_iv (EV, METHOD_SELECT) - const_iv (EV, METHOD_POLL) - const_iv (EV, METHOD_EPOLL) - const_iv (EV, METHOD_KQUEUE) - const_iv (EV, METHOD_DEVPOLL) - const_iv (EV, METHOD_PORT) - const_iv (EV, METHOD_ANY) + const_iv (EV, BACKEND_SELECT) + const_iv (EV, BACKEND_POLL) + const_iv (EV, BACKEND_EPOLL) + const_iv (EV, BACKEND_KQUEUE) + const_iv (EV, BACKEND_DEVPOLL) + const_iv (EV, BACKEND_PORT) + const_iv (EV, FLAG_AUTO) + const_iv (EV, FLAG_NOENV) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) @@ -351,7 +398,7 @@ evapi.sv_fileno = sv_fileno; evapi.sv_signum = sv_signum; evapi.now = ev_now; - evapi.method = ev_method; + evapi.backend = ev_backend; evapi.unloop = ev_unloop; evapi.time = ev_time; evapi.loop = ev_loop; @@ -373,22 +420,24 @@ evapi.check_stop = ev_check_stop; evapi.child_start = ev_child_start; evapi.child_stop = ev_child_stop; + evapi.ref = ev_ref; + evapi.unref = ev_unref; sv_setiv (sv, (IV)&evapi); SvREADONLY_on (sv); } -#ifndef WIN32 +#ifndef _WIN32 pthread_atfork (0, 0, ev_default_fork); #endif } NV ev_now () -int ev_method () +unsigned int ev_backend () NV ev_time () -int ev_default_loop (int methods = EVMETHOD_AUTO) +unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) void ev_loop (int flags = 0) @@ -481,7 +530,7 @@ struct ev_child *child (int pid, SV *cb) ALIAS: - check_ns = 1 + child_ns = 1 CODE: RETVAL = e_new (sizeof (struct ev_child), cb); ev_child_set (RETVAL, pid); @@ -489,6 +538,14 @@ OUTPUT: RETVAL +void once (SV *fh, int events, SV *timeout, SV *cb) + CODE: + ev_once ( + sv_fileno (fh), events, + SvOK (timeout) ? SvNV (timeout) : -1., + e_once_cb, + newSVsv (cb) + ); PROTOTYPES: DISABLE @@ -798,7 +855,7 @@ OUTPUT: RETVAL -#ifndef WIN32 +#ifndef _WIN32 MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ @@ -879,7 +936,7 @@ int evdns_resolv_conf_parse (int flags, const char *filename) -#ifdef MS_WINDOWS +#ifdef _WIN32 int evdns_config_windows_nameservers ()