ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV-ADNS/ADNS.xs
(Generate patch)

Comparing EV-ADNS/ADNS.xs (file contents):
Revision 1.1 by root, Sat Dec 1 13:53:11 2007 UTC vs.
Revision 1.2 by root, Sat Dec 1 14:14:00 2007 UTC

5#include <poll.h> 5#include <poll.h>
6#include <adns.h> 6#include <adns.h>
7 7
8#include "EVAPI.h" 8#include "EVAPI.h"
9 9
10static HV *stash;
10static adns_state ads; 11static adns_state ads;
11 12
12struct ctx 13struct ctx
13{ 14{
14 SV *req; 15 SV *self;
16 adns_query query;
15 SV *cb; 17 SV *cb;
16}; 18};
17 19
18static void 20static void
19process () 21process ()
33static struct pollfd *fds; 35static struct pollfd *fds;
34static int nfd; 36static int nfd;
35static ev_io *iow; 37static ev_io *iow;
36static ev_timer tw; 38static ev_timer tw;
37static ev_prepare prepare_ev; 39static ev_prepare prepare_ev;
38static struct timeval *tv_now; 40static struct timeval tv_now;
39 41
40static void 42static void
41update_now (EV_P) 43update_now (EV_P)
42{ 44{
43 ev_tstamp t = ev_now (EV_P); 45 ev_tstamp t = ev_now ();
44 46
45 tv.tv_sec = (long)t; 47 tv_now.tv_sec = (long)t;
46 tv.tv_usec = (long)((t - (ev_tstamp)tv.tv_sec) * 1e-6); 48 tv_now.tv_usec = (long)((t - (ev_tstamp)tv_now.tv_sec) * 1e-6);
47} 49}
48 50
49static void 51static void
50timer_cb (EV_P_ ev_timer *w, int revents) 52timer_cb (EV_P_ ev_timer *w, int revents)
51{ 53{
100 102
101PROTOTYPES: ENABLE 103PROTOTYPES: ENABLE
102 104
103BOOT: 105BOOT:
104{ 106{
107 stash = gv_stashpv ("EV::ADNS", 1);
105#if 0 108#if 0
106 HV *stash = gv_stashpv ("EV::ADNS", 1);
107 109
108 static const struct { 110 static const struct {
109 const char *name; 111 const char *name;
110 IV iv; 112 IV iv;
111 } *civ, const_iv[] = { 113 } *civ, const_iv[] = {
200 ev_init (&tw, timer_cb); 202 ev_init (&tw, timer_cb);
201 203
202 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0); 204 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0);
203} 205}
204 206
205int adns_submit (char *owner, int type, int flags, SV *cb) 207void adns_submit (char *owner, int type, int flags, SV *cb)
206 CODE: 208 PPCODE:
207{ 209{
210 SV *csv = NEWSV (0, sizeof (struct ctx));
208 struct ctx *c = (struct ctx *)malloc (sizeof (ctx)); 211 struct ctx *c = (struct ctx *)SvPVX (csv);
209 adns_query q;
210 int r = adns_submit (owner, type, flags, (void *)c, &q); 212 int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query);
211 213
212 if (r) 214 if (r)
213 { 215 {
214 free (c); 216 SvREFCNT_dec (csv);
215 XSRETURN_EMPTY; 217 XSRETURN_EMPTY;
216 } 218 }
217} 219 else
220 {
221 SvPOK_only (csv);
222 SvCUR_set (csv, sizeof (struct ctx));
223 c->self = csv;
224 c->cb = newSVsv (cb);
218 225
226 if (GIMME_V != G_VOID)
227 {
228 csv = sv_2mortal (newRV_inc (csv));
229 sv_bless (csv, stash);
230 XPUSHs (csv);
231 }
232 }
233}
219 234
235void DESTROY (SV *req)
236 CODE:
237{
238 struct ctx *c;
220 239
240 if (!(SvROK (req) && SvOBJECT (SvRV (req))
241 && (SvSTASH (SvRV (req)) == stash)))
242 croak ("object is not of type EV::ADNS");
243
244 c = (struct ctx *)SvPVX (SvRV (req));
245
246 if (c->cb)
247 {
248 adns_cancel (c->query);
249 SvREFCNT_dec (c->cb);
250 }
251
252 SvREFCNT_dec (c->self);
253}
254
255
256
257

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines