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

Comparing cvsroot/EV-ADNS/ADNS.xs (file contents):
Revision 1.3 by root, Sat Dec 1 14:37:46 2007 UTC vs.
Revision 1.5 by root, Sat Dec 1 15:54:40 2007 UTC

22{ 22{
23 dSP; 23 dSP;
24 24
25 for (;;) 25 for (;;)
26 { 26 {
27 adns_query q; 27 adns_query q = 0;
28 adns_answer *a; 28 adns_answer *a;
29 void *ctx; 29 void *ctx;
30 SV *cb; 30 SV *cb;
31 struct ctx *c; 31 struct ctx *c;
32 int r = adns_check (ads, &q, &a, &ctx); 32 int r = adns_check (ads, &q, &a, &ctx);
33 33
34 printf ("check %d\n", r);//D
34 if (r) 35 if (r)
35 break; 36 break;
36 37
37 c = (struct ctx *)ctx; 38 c = (struct ctx *)ctx;
38 cb = c->cb; 39 cb = c->cb;
39 c->cb = 0; 40 c->cb = 0;
40 ev_unref (); 41 ev_unref ();
41 42
42 PUSHMARK (SP); 43 PUSHMARK (SP);
44
45 XPUSHs (sv_2mortal (newSViv (a->status)));
46 free (a);
47
48 PUTBACK;
43 call_sv (cb, G_VOID | G_DISCARD | G_EVAL); 49 call_sv (cb, G_VOID | G_DISCARD | G_EVAL);
50 SPAGAIN;
44 51
45 SvREFCNT_dec (cb); 52 SvREFCNT_dec (cb);
53 SvREFCNT_dec (c->self);
46 } 54 }
47} 55}
48 56
49static struct pollfd *fds; 57static struct pollfd *fds;
50static int nfd; 58static int nfd, mfd;
51static ev_io *iow; 59static ev_io *iow;
52static ev_timer tw; 60static ev_timer tw;
53static ev_prepare prepare_ev; 61static ev_prepare prepare_ev;
54static struct timeval tv_now; 62static struct timeval tv_now;
55 63
90 98
91 process (); 99 process ();
92 100
93 update_now (EV_A); 101 update_now (EV_A);
94 102
103 nfd = mfd;
104
95 while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now)) 105 while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now))
96 { 106 {
107 mfd = nfd;
108
97 free (iow); iow = malloc (nfd * sizeof (struct pollfd)); 109 free (iow); iow = malloc (mfd * sizeof (struct pollfd));
98 free (fds); fds = malloc (nfd * sizeof (ev_io)); 110 free (fds); fds = malloc (mfd * sizeof (ev_io));
99 } 111 }
112
113 printf ("to %d\n", timeout);//d
100 114
101 ev_timer_set (&tw, timeout * 1e-3, 0.); 115 ev_timer_set (&tw, timeout * 1e-3, 0.);
102 ev_timer_start (EV_A_ &tw); 116 ev_timer_start (EV_A_ &tw);
103 117
104 // create on ev_io per pollfd 118 // create one ev_io per pollfd
105 for (i = 0; i < nfd; ++i) 119 for (i = 0; i < nfd; ++i)
106 { 120 {
107 ev_io_init (iow + i, io_cb, fds [i].fd, 121 ev_io_init (iow + i, io_cb, fds [i].fd,
108 ((fds [i].events & POLLIN ? EV_READ : 0) 122 ((fds [i].events & POLLIN ? EV_READ : 0)
109 | (fds [i].events & POLLOUT ? EV_WRITE : 0))); 123 | (fds [i].events & POLLOUT ? EV_WRITE : 0)));
223 struct ctx *c = (struct ctx *)SvPVX (csv); 237 struct ctx *c = (struct ctx *)SvPVX (csv);
224 int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query); 238 int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query);
225 239
226 if (r) 240 if (r)
227 { 241 {
228 printf ("errn %d\n", r);//D
229 SvREFCNT_dec (csv); 242 SvREFCNT_dec (csv);
230 XSRETURN_EMPTY; 243 XSRETURN_EMPTY;
231 } 244 }
232 else 245 else
233 { 246 {
261 { 274 {
262 ev_unref (); 275 ev_unref ();
263 adns_cancel (c->query); 276 adns_cancel (c->query);
264 SvREFCNT_dec (c->cb); 277 SvREFCNT_dec (c->cb);
265 } 278 }
266
267 SvREFCNT_dec (c->self);
268} 279}
269 280
270 281
271 282
272 283

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines