… | |
… | |
18 | }; |
18 | }; |
19 | |
19 | |
20 | static void |
20 | static void |
21 | process () |
21 | process () |
22 | { |
22 | { |
|
|
23 | dSP; |
|
|
24 | |
23 | for (;;) |
25 | for (;;) |
24 | { |
26 | { |
25 | adns_query q; |
27 | adns_query q; |
26 | adns_answer *a; |
28 | adns_answer *a; |
27 | void *c; |
29 | void *ctx; |
|
|
30 | SV *cb; |
|
|
31 | struct ctx *c; |
28 | int r = adns_check (ads, &q, &a, &c); |
32 | int r = adns_check (ads, &q, &a, &ctx); |
29 | |
33 | |
30 | if (r) |
34 | if (r) |
31 | 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); |
32 | } |
46 | } |
33 | } |
47 | } |
34 | |
48 | |
35 | static struct pollfd *fds; |
49 | static struct pollfd *fds; |
36 | static int nfd; |
50 | static int nfd; |
… | |
… | |
103 | PROTOTYPES: ENABLE |
117 | PROTOTYPES: ENABLE |
104 | |
118 | |
105 | BOOT: |
119 | BOOT: |
106 | { |
120 | { |
107 | stash = gv_stashpv ("EV::ADNS", 1); |
121 | stash = gv_stashpv ("EV::ADNS", 1); |
108 | #if 0 |
|
|
109 | |
122 | |
110 | static const struct { |
123 | static const struct { |
111 | const char *name; |
124 | const char *name; |
112 | IV iv; |
125 | IV iv; |
113 | } *civ, const_iv[] = { |
126 | } *civ, const_iv[] = { |
114 | # define const_iv(pfx, name) { # name, (IV) adns_ ## name }, |
127 | # define const_iv(name) { # name, (IV) adns_ ## name }, |
115 | const_iv (if_none) |
128 | const_iv (if_none) |
116 | const_iv (if_noenv) |
129 | const_iv (if_noenv) |
117 | const_iv (if_noerrprint) |
130 | const_iv (if_noerrprint) |
118 | const_iv (if_noserverwarn) |
131 | const_iv (if_noserverwarn) |
119 | const_iv (if_debug) |
132 | const_iv (if_debug) |
… | |
… | |
190 | const_iv (s_max_permfail) |
203 | const_iv (s_max_permfail) |
191 | }; |
204 | }; |
192 | |
205 | |
193 | 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; ) |
194 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
207 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
195 | #endif |
|
|
196 | |
208 | |
197 | I_EV_API ("EV::ADNS"); |
209 | I_EV_API ("EV::ADNS"); |
198 | |
210 | |
199 | 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); |
200 | ev_unref (); |
212 | ev_unref (); |
… | |
… | |
202 | ev_init (&tw, timer_cb); |
214 | ev_init (&tw, timer_cb); |
203 | |
215 | |
204 | 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); |
205 | } |
217 | } |
206 | |
218 | |
207 | void adns_submit (char *owner, int type, int flags, SV *cb) |
219 | void submit (char *owner, int type, int flags, SV *cb) |
208 | PPCODE: |
220 | PPCODE: |
209 | { |
221 | { |
210 | SV *csv = NEWSV (0, sizeof (struct ctx)); |
222 | SV *csv = NEWSV (0, sizeof (struct ctx)); |
211 | struct ctx *c = (struct ctx *)SvPVX (csv); |
223 | struct ctx *c = (struct ctx *)SvPVX (csv); |
212 | int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query); |
224 | int r = adns_submit (ads, owner, type, flags, (void *)c, &c->query); |
213 | |
225 | |
214 | if (r) |
226 | if (r) |
215 | { |
227 | { |
|
|
228 | printf ("errn %d\n", r);//D |
216 | SvREFCNT_dec (csv); |
229 | SvREFCNT_dec (csv); |
217 | XSRETURN_EMPTY; |
230 | XSRETURN_EMPTY; |
218 | } |
231 | } |
219 | else |
232 | else |
220 | { |
233 | { |
|
|
234 | ev_ref (); |
221 | SvPOK_only (csv); |
235 | SvPOK_only (csv); |
222 | SvCUR_set (csv, sizeof (struct ctx)); |
236 | SvCUR_set (csv, sizeof (struct ctx)); |
223 | c->self = csv; |
237 | c->self = csv; |
224 | c->cb = newSVsv (cb); |
238 | c->cb = newSVsv (cb); |
225 | |
239 | |
… | |
… | |
243 | |
257 | |
244 | c = (struct ctx *)SvPVX (SvRV (req)); |
258 | c = (struct ctx *)SvPVX (SvRV (req)); |
245 | |
259 | |
246 | if (c->cb) |
260 | if (c->cb) |
247 | { |
261 | { |
|
|
262 | ev_unref (); |
248 | adns_cancel (c->query); |
263 | adns_cancel (c->query); |
249 | SvREFCNT_dec (c->cb); |
264 | SvREFCNT_dec (c->cb); |
250 | } |
265 | } |
251 | |
266 | |
252 | SvREFCNT_dec (c->self); |
267 | SvREFCNT_dec (c->self); |