--- cvsroot/EV-ADNS/ADNS.xs 2007/12/01 14:14:00 1.2 +++ cvsroot/EV-ADNS/ADNS.xs 2007/12/01 15:54:40 1.5 @@ -20,20 +20,42 @@ static void process () { + dSP; + for (;;) { - adns_query q; + adns_query q = 0; adns_answer *a; - void *c; - int r = adns_check (ads, &q, &a, &c); + void *ctx; + SV *cb; + struct ctx *c; + int r = adns_check (ads, &q, &a, &ctx); + printf ("check %d\n", r);//D if (r) break; + + c = (struct ctx *)ctx; + cb = c->cb; + c->cb = 0; + ev_unref (); + + PUSHMARK (SP); + + XPUSHs (sv_2mortal (newSViv (a->status))); + free (a); + + PUTBACK; + call_sv (cb, G_VOID | G_DISCARD | G_EVAL); + SPAGAIN; + + SvREFCNT_dec (cb); + SvREFCNT_dec (c->self); } } static struct pollfd *fds; -static int nfd; +static int nfd, mfd; static ev_io *iow; static ev_timer tw; static ev_prepare prepare_ev; @@ -78,16 +100,22 @@ update_now (EV_A); + nfd = mfd; + while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now)) { - free (iow); iow = malloc (nfd * sizeof (struct pollfd)); - free (fds); fds = malloc (nfd * sizeof (ev_io)); + mfd = nfd; + + free (iow); iow = malloc (mfd * sizeof (struct pollfd)); + free (fds); fds = malloc (mfd * sizeof (ev_io)); } + printf ("to %d\n", timeout);//d + ev_timer_set (&tw, timeout * 1e-3, 0.); ev_timer_start (EV_A_ &tw); - // create on ev_io per pollfd + // create one ev_io per pollfd for (i = 0; i < nfd; ++i) { ev_io_init (iow + i, io_cb, fds [i].fd, @@ -105,13 +133,12 @@ BOOT: { stash = gv_stashpv ("EV::ADNS", 1); -#if 0 static const struct { const char *name; IV iv; } *civ, const_iv[] = { -# define const_iv(pfx, name) { # name, (IV) adns_ ## name }, +# define const_iv(name) { # name, (IV) adns_ ## name }, const_iv (if_none) const_iv (if_noenv) const_iv (if_noerrprint) @@ -192,7 +219,6 @@ for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); -#endif I_EV_API ("EV::ADNS"); @@ -204,7 +230,7 @@ adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0); } -void adns_submit (char *owner, int type, int flags, SV *cb) +void submit (char *owner, int type, int flags, SV *cb) PPCODE: { SV *csv = NEWSV (0, sizeof (struct ctx)); @@ -218,6 +244,7 @@ } else { + ev_ref (); SvPOK_only (csv); SvCUR_set (csv, sizeof (struct ctx)); c->self = csv; @@ -245,11 +272,10 @@ if (c->cb) { + ev_unref (); adns_cancel (c->query); SvREFCNT_dec (c->cb); } - - SvREFCNT_dec (c->self); }