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.9 by root, Sat Dec 1 22:36:10 2007 UTC vs.
Revision 1.12 by root, Fri Dec 7 23:54:13 2007 UTC

4 4
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
10static HV *stash;
11static adns_state ads;
12 9
13struct ctx 10struct ctx
14{ 11{
15 SV *self; 12 SV *self;
16 adns_query query; 13 adns_query query;
26 23
27 return newRV_noinc ((SV *)av); 24 return newRV_noinc ((SV *)av);
28} 25}
29 26
30static void 27static void
31process () 28process (adns_state ads)
32{ 29{
33 dSP; 30 dSP;
34 31
35 for (;;) 32 for (;;)
36 { 33 {
216static struct pollfd *fds; 213static struct pollfd *fds;
217static int nfd, mfd; 214static int nfd, mfd;
218static ev_io *iow; 215static ev_io *iow;
219static ev_timer tw; 216static ev_timer tw;
220static ev_idle iw; 217static ev_idle iw;
221static ev_prepare prepare_ev; 218static ev_prepare pw;
222static struct timeval tv_now; 219static struct timeval tv_now;
223 220
224static void 221static void
225update_now (EV_P) 222update_now (EV_P)
226{ 223{
227 ev_tstamp t = ev_now (); 224 ev_tstamp t = ev_now ();
228 225
229 tv_now.tv_sec = (long)t; 226 tv_now.tv_sec = (long)t;
230 tv_now.tv_usec = (long)((t - (ev_tstamp)tv_now.tv_sec) * 1e-6); 227 tv_now.tv_usec = (long)((t - (ev_tstamp)tv_now.tv_sec) * 1e6);
231} 228}
232 229
233static void 230static void
234idle_cb (EV_P_ ev_idle *w, int revents) 231idle_cb (EV_P_ ev_idle *w, int revents)
235{ 232{
237} 234}
238 235
239static void 236static void
240timer_cb (EV_P_ ev_timer *w, int revents) 237timer_cb (EV_P_ ev_timer *w, int revents)
241{ 238{
239 adns_state ads = (adns_state)w->data;
240 update_now ();
241
242 adns_processtimeouts (ads, &tv_now);
242} 243}
243 244
244static void 245static void
245io_cb (EV_P_ ev_io *w, int revents) 246io_cb (EV_P_ ev_io *w, int revents)
246{ 247{
248 adns_state ads = (adns_state)w->data;
247 update_now (EV_A); 249 update_now (EV_A);
248 250
249 if (revents & EV_READ ) adns_processreadable (ads, w->fd, &tv_now); 251 if (revents & EV_READ ) adns_processreadable (ads, w->fd, &tv_now);
250 if (revents & EV_WRITE) adns_processwriteable (ads, w->fd, &tv_now); 252 if (revents & EV_WRITE) adns_processwriteable (ads, w->fd, &tv_now);
251} 253}
254static void 256static void
255prepare_cb (EV_P_ ev_prepare *w, int revents) 257prepare_cb (EV_P_ ev_prepare *w, int revents)
256{ 258{
257 int i; 259 int i;
258 int timeout = 3600000; 260 int timeout = 3600000;
261 adns_state ads = (adns_state)w->data;
259 262
260 if (ev_is_active (&tw)) 263 if (ev_is_active (&tw))
261 { 264 {
262 ev_ref (); 265 ev_ref ();
263 ev_timer_stop (EV_A_ &tw); 266 ev_timer_stop (EV_A_ &tw);
270 { 273 {
271 ev_ref (); 274 ev_ref ();
272 ev_io_stop (EV_A_ iow + i); 275 ev_io_stop (EV_A_ iow + i);
273 } 276 }
274 277
275 process (); 278 process (ads);
276
277 update_now (EV_A); 279 update_now (EV_A);
278 280
279 nfd = mfd; 281 nfd = mfd;
280 282
281 while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now)) 283 while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now))
299 301
300 ev_io_start (EV_A_ iow + i); 302 ev_io_start (EV_A_ iow + i);
301 ev_unref (); 303 ev_unref ();
302 } 304 }
303} 305}
306
307static HV *stash;
308static adns_state ads;
304 309
305MODULE = EV::ADNS PACKAGE = EV::ADNS 310MODULE = EV::ADNS PACKAGE = EV::ADNS
306 311
307PROTOTYPES: ENABLE 312PROTOTYPES: ENABLE
308 313
396 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 401 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
397 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 402 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
398 403
399 I_EV_API ("EV::ADNS"); 404 I_EV_API ("EV::ADNS");
400 405
406 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0);
407
401 ev_prepare_init (&prepare_ev, prepare_cb); 408 ev_prepare_init (&pw, prepare_cb);
409 pw.data = (void *)ads;
402 ev_prepare_start (EV_DEFAULT_ &prepare_ev); 410 ev_prepare_start (EV_DEFAULT_ &pw);
403 ev_unref (); 411 ev_unref ();
404 412
405 ev_init (&iw, idle_cb); 413 ev_init (&iw, idle_cb); ev_set_priority (&iw, EV_MINPRI);
414 iw.data = (void *)ads;
406 ev_init (&tw, timer_cb); 415 ev_init (&tw, timer_cb);
407 416 tw.data = (void *)ads;
408 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0);
409} 417}
410 418
411void submit (char *owner, int type, int flags, SV *cb) 419void submit (char *owner, int type, int flags, SV *cb)
412 PPCODE: 420 PPCODE:
413{ 421{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines