EV-ADNS

 view release on metacpan or  search on metacpan

ADNS.xs  view on Meta::CPAN

    const_iv (r_addr)

    const_iv (s_ok)
    const_iv (s_nomemory)
    const_iv (s_unknownrrtype)
    const_iv (s_systemfail)
    const_iv (s_max_localfail)
    const_iv (s_timeout)
    const_iv (s_allservfail)
    const_iv (s_norecurse)
    const_iv (s_invalidresponse)
    const_iv (s_unknownformat)
    const_iv (s_max_remotefail)
    const_iv (s_rcodeservfail)
    const_iv (s_rcodeformaterror)
    const_iv (s_rcodenotimplemented)
    const_iv (s_rcoderefused)
    const_iv (s_rcodeunknown)
    const_iv (s_max_tempfail)
    const_iv (s_inconsistent)
    const_iv (s_prohibitedcname)
    const_iv (s_answerdomaininvalid)
    const_iv (s_answerdomaintoolong)
    const_iv (s_invaliddata)
    const_iv (s_max_misconfig)
    const_iv (s_querydomainwrong)
    const_iv (s_querydomaininvalid)
    const_iv (s_querydomaintoolong)
    const_iv (s_max_misquery)
    const_iv (s_nxdomain)
    const_iv (s_nodata)
    const_iv (s_max_permfail)
  };

  for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
    newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));

  I_EV_API ("EV::ADNS");

  adns_init (&ads, DEFAULT_INIT_FLAGS, 0);

  ev_prepare_init (&pw, prepare_cb);
  pw.data = (void *)ads;

  ev_init (&iw, idle_cb); ev_set_priority (&iw, EV_MINPRI);
  iw.data = (void *)ads;
  ev_init (&tw, timer_cb);
  tw.data = (void *)ads;
}

int
reinit (SV *flags = &PL_sv_undef, SV *str = &PL_sv_undef)
	CODE:
{
        int initflags = SvOK (flags) ? SvIV (flags) : DEFAULT_INIT_FLAGS;
        adns_finish (ads);
        adns_init_logfn (&ads, initflags, SvOK (str) ? SvPVbyte_nolen (str) : 0, 0, 0);
}

void submit (char *owner, int type, int flags, SV *cb)
	PPCODE:
{
        SV *csv = NEWSV (0, sizeof (struct ctx));
	struct ctx *c = (struct ctx *)SvPVX (csv);
        int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query);

        outstanding_inc (ads);

        if (r)
          {
            SvREFCNT_dec (csv);
            croak ("EV::ADNS::submit: %s", strerror ((errno = r)));
          }

        SvPOK_only (csv);
        SvCUR_set (csv, sizeof (struct ctx));

        c->self = csv;
        c->cb   = newSVsv (cb);
        c->ads  = ads;

        if (!ev_is_active (&iw))
          ev_idle_start (EV_DEFAULT, &iw);

        if (GIMME_V != G_VOID)
          {
            csv = sv_2mortal (newRV_inc (csv));
            sv_bless (csv, stash);
            XPUSHs (csv);
          }
}

void DESTROY (SV *req)
	ALIAS:
        cancel = 1
	CODE:
{
        struct ctx *c;

        if (!(SvROK (req) && SvOBJECT (SvRV (req))
              && (SvSTASH (SvRV (req)) == stash)))
          croak ("object is not of type EV::ADNS");
        
        c = (struct ctx *)SvPVX (SvRV (req));

        if (c->cb)
          {
            SvREFCNT_dec (c->cb);
            c->cb = 0; outstanding_dec (c->ads);
            adns_cancel (c->query);
            SvREFCNT_dec (c->self);
          }
}



( run in 2.806 seconds using v1.01-cache-2.11-cpan-71847e10f99 )