--- cvsroot/EV-ADNS/ADNS.xs 2007/12/01 21:29:08 1.8 +++ cvsroot/EV-ADNS/ADNS.xs 2007/12/07 23:54:13 1.12 @@ -7,9 +7,6 @@ #include "EVAPI.h" -static HV *stash; -static adns_state ads; - struct ctx { SV *self; @@ -28,7 +25,7 @@ } static void -process () +process (adns_state ads) { dSP; @@ -217,7 +214,8 @@ static int nfd, mfd; static ev_io *iow; static ev_timer tw; -static ev_prepare prepare_ev; +static ev_idle iw; +static ev_prepare pw; static struct timeval tv_now; static void @@ -226,17 +224,28 @@ ev_tstamp t = ev_now (); tv_now.tv_sec = (long)t; - tv_now.tv_usec = (long)((t - (ev_tstamp)tv_now.tv_sec) * 1e-6); + tv_now.tv_usec = (long)((t - (ev_tstamp)tv_now.tv_sec) * 1e6); +} + +static void +idle_cb (EV_P_ ev_idle *w, int revents) +{ + ev_idle_stop (EV_A_ w); } static void timer_cb (EV_P_ ev_timer *w, int revents) { + adns_state ads = (adns_state)w->data; + update_now (); + + adns_processtimeouts (ads, &tv_now); } static void io_cb (EV_P_ ev_io *w, int revents) { + adns_state ads = (adns_state)w->data; update_now (EV_A); if (revents & EV_READ ) adns_processreadable (ads, w->fd, &tv_now); @@ -249,6 +258,7 @@ { int i; int timeout = 3600000; + adns_state ads = (adns_state)w->data; if (ev_is_active (&tw)) { @@ -256,14 +266,16 @@ ev_timer_stop (EV_A_ &tw); } + if (ev_is_active (&iw)) + ev_idle_stop (EV_A_ &iw); + for (i = 0; i < nfd; ++i) { ev_ref (); ev_io_stop (EV_A_ iow + i); } - process (); - + process (ads); update_now (EV_A); nfd = mfd; @@ -292,6 +304,9 @@ } } +static HV *stash; +static adns_state ads; + MODULE = EV::ADNS PACKAGE = EV::ADNS PROTOTYPES: ENABLE @@ -388,12 +403,17 @@ I_EV_API ("EV::ADNS"); - ev_prepare_init (&prepare_ev, prepare_cb); ev_prepare_start (EV_DEFAULT_ &prepare_ev); + adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0); + + ev_prepare_init (&pw, prepare_cb); + pw.data = (void *)ads; + ev_prepare_start (EV_DEFAULT_ &pw); ev_unref (); + ev_init (&iw, idle_cb); ev_set_priority (&iw, EV_MINPRI); + iw.data = (void *)ads; ev_init (&tw, timer_cb); - - adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0); + tw.data = (void *)ads; } void submit (char *owner, int type, int flags, SV *cb) @@ -418,6 +438,9 @@ c->self = csv; c->cb = newSVsv (cb); + if (!ev_is_active (&iw)) + ev_idle_start (EV_A_ &iw); + if (GIMME_V != G_VOID) { csv = sv_2mortal (newRV_inc (csv));