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.3 by root, Sat Dec 1 14:37:46 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 ()
20{ 22{
23 dSP;
24
21 for (;;) 25 for (;;)
22 { 26 {
23 adns_query q; 27 adns_query q;
24 adns_answer *a; 28 adns_answer *a;
25 void *c; 29 void *ctx;
30 SV *cb;
31 struct ctx *c;
26 int r = adns_check (ads, &q, &a, &c); 32 int r = adns_check (ads, &q, &a, &ctx);
27 33
28 if (r) 34 if (r)
29 break; 35 break;
36
37 c = (struct ctx *)ctx;
38 cb = c->cb;
39 c->cb = 0;
40 ev_unref ();
41
42 PUSHMARK (SP);
43 call_sv (cb, G_VOID | G_DISCARD | G_EVAL);
44
45 SvREFCNT_dec (cb);
30 } 46 }
31} 47}
32 48
33static struct pollfd *fds; 49static struct pollfd *fds;
34static int nfd; 50static int nfd;
35static ev_io *iow; 51static ev_io *iow;
36static ev_timer tw; 52static ev_timer tw;
37static ev_prepare prepare_ev; 53static ev_prepare prepare_ev;
38static struct timeval *tv_now; 54static struct timeval tv_now;
39 55
40static void 56static void
41update_now (EV_P) 57update_now (EV_P)
42{ 58{
43 ev_tstamp t = ev_now (EV_P); 59 ev_tstamp t = ev_now ();
44 60
45 tv.tv_sec = (long)t; 61 tv_now.tv_sec = (long)t;
46 tv.tv_usec = (long)((t - (ev_tstamp)tv.tv_sec) * 1e-6); 62 tv_now.tv_usec = (long)((t - (ev_tstamp)tv_now.tv_sec) * 1e-6);
47} 63}
48 64
49static void 65static void
50timer_cb (EV_P_ ev_timer *w, int revents) 66timer_cb (EV_P_ ev_timer *w, int revents)
51{ 67{
100 116
101PROTOTYPES: ENABLE 117PROTOTYPES: ENABLE
102 118
103BOOT: 119BOOT:
104{ 120{
105#if 0
106 HV *stash = gv_stashpv ("EV::ADNS", 1); 121 stash = gv_stashpv ("EV::ADNS", 1);
107 122
108 static const struct { 123 static const struct {
109 const char *name; 124 const char *name;
110 IV iv; 125 IV iv;
111 } *civ, const_iv[] = { 126 } *civ, const_iv[] = {
112# define const_iv(pfx, name) { # name, (IV) adns_ ## name }, 127# define const_iv(name) { # name, (IV) adns_ ## name },
113 const_iv (if_none) 128 const_iv (if_none)
114 const_iv (if_noenv) 129 const_iv (if_noenv)
115 const_iv (if_noerrprint) 130 const_iv (if_noerrprint)
116 const_iv (if_noserverwarn) 131 const_iv (if_noserverwarn)
117 const_iv (if_debug) 132 const_iv (if_debug)
188 const_iv (s_max_permfail) 203 const_iv (s_max_permfail)
189 }; 204 };
190 205
191 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 206 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
192 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 207 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
193#endif
194 208
195 I_EV_API ("EV::ADNS"); 209 I_EV_API ("EV::ADNS");
196 210
197 ev_prepare_init (&prepare_ev, prepare_cb); ev_prepare_start (EV_DEFAULT_ &prepare_ev); 211 ev_prepare_init (&prepare_ev, prepare_cb); ev_prepare_start (EV_DEFAULT_ &prepare_ev);
198 ev_unref (); 212 ev_unref ();
200 ev_init (&tw, timer_cb); 214 ev_init (&tw, timer_cb);
201 215
202 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0); 216 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0);
203} 217}
204 218
205int adns_submit (char *owner, int type, int flags, SV *cb) 219void submit (char *owner, int type, int flags, SV *cb)
206 CODE: 220 PPCODE:
207{ 221{
222 SV *csv = NEWSV (0, sizeof (struct ctx));
208 struct ctx *c = (struct ctx *)malloc (sizeof (ctx)); 223 struct ctx *c = (struct ctx *)SvPVX (csv);
209 adns_query q;
210 int r = adns_submit (owner, type, flags, (void *)c, &q); 224 int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query);
211 225
212 if (r) 226 if (r)
213 { 227 {
214 free (c); 228 printf ("errn %d\n", r);//D
229 SvREFCNT_dec (csv);
215 XSRETURN_EMPTY; 230 XSRETURN_EMPTY;
216 } 231 }
217} 232 else
233 {
234 ev_ref ();
235 SvPOK_only (csv);
236 SvCUR_set (csv, sizeof (struct ctx));
237 c->self = csv;
238 c->cb = newSVsv (cb);
218 239
240 if (GIMME_V != G_VOID)
241 {
242 csv = sv_2mortal (newRV_inc (csv));
243 sv_bless (csv, stash);
244 XPUSHs (csv);
245 }
246 }
247}
219 248
249void DESTROY (SV *req)
250 CODE:
251{
252 struct ctx *c;
220 253
254 if (!(SvROK (req) && SvOBJECT (SvRV (req))
255 && (SvSTASH (SvRV (req)) == stash)))
256 croak ("object is not of type EV::ADNS");
257
258 c = (struct ctx *)SvPVX (SvRV (req));
259
260 if (c->cb)
261 {
262 ev_unref ();
263 adns_cancel (c->query);
264 SvREFCNT_dec (c->cb);
265 }
266
267 SvREFCNT_dec (c->self);
268}
269
270
271
272

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines