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.8 by root, Sat Dec 1 21:29:08 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 {
215 212
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;
217static ev_idle iw;
220static ev_prepare prepare_ev; 218static ev_prepare pw;
221static struct timeval tv_now; 219static struct timeval tv_now;
222 220
223static void 221static void
224update_now (EV_P) 222update_now (EV_P)
225{ 223{
226 ev_tstamp t = ev_now (); 224 ev_tstamp t = ev_now ();
227 225
228 tv_now.tv_sec = (long)t; 226 tv_now.tv_sec = (long)t;
229 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);
228}
229
230static void
231idle_cb (EV_P_ ev_idle *w, int revents)
232{
233 ev_idle_stop (EV_A_ w);
230} 234}
231 235
232static void 236static void
233timer_cb (EV_P_ ev_timer *w, int revents) 237timer_cb (EV_P_ ev_timer *w, int revents)
234{ 238{
239 adns_state ads = (adns_state)w->data;
240 update_now ();
241
242 adns_processtimeouts (ads, &tv_now);
235} 243}
236 244
237static void 245static void
238io_cb (EV_P_ ev_io *w, int revents) 246io_cb (EV_P_ ev_io *w, int revents)
239{ 247{
248 adns_state ads = (adns_state)w->data;
240 update_now (EV_A); 249 update_now (EV_A);
241 250
242 if (revents & EV_READ ) adns_processreadable (ads, w->fd, &tv_now); 251 if (revents & EV_READ ) adns_processreadable (ads, w->fd, &tv_now);
243 if (revents & EV_WRITE) adns_processwriteable (ads, w->fd, &tv_now); 252 if (revents & EV_WRITE) adns_processwriteable (ads, w->fd, &tv_now);
244} 253}
247static void 256static void
248prepare_cb (EV_P_ ev_prepare *w, int revents) 257prepare_cb (EV_P_ ev_prepare *w, int revents)
249{ 258{
250 int i; 259 int i;
251 int timeout = 3600000; 260 int timeout = 3600000;
261 adns_state ads = (adns_state)w->data;
252 262
253 if (ev_is_active (&tw)) 263 if (ev_is_active (&tw))
254 { 264 {
255 ev_ref (); 265 ev_ref ();
256 ev_timer_stop (EV_A_ &tw); 266 ev_timer_stop (EV_A_ &tw);
257 } 267 }
258 268
269 if (ev_is_active (&iw))
270 ev_idle_stop (EV_A_ &iw);
271
259 for (i = 0; i < nfd; ++i) 272 for (i = 0; i < nfd; ++i)
260 { 273 {
261 ev_ref (); 274 ev_ref ();
262 ev_io_stop (EV_A_ iow + i); 275 ev_io_stop (EV_A_ iow + i);
263 } 276 }
264 277
265 process (); 278 process (ads);
266
267 update_now (EV_A); 279 update_now (EV_A);
268 280
269 nfd = mfd; 281 nfd = mfd;
270 282
271 while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now)) 283 while (adns_beforepoll (ads, fds, &nfd, &timeout, &tv_now))
289 301
290 ev_io_start (EV_A_ iow + i); 302 ev_io_start (EV_A_ iow + i);
291 ev_unref (); 303 ev_unref ();
292 } 304 }
293} 305}
306
307static HV *stash;
308static adns_state ads;
294 309
295MODULE = EV::ADNS PACKAGE = EV::ADNS 310MODULE = EV::ADNS PACKAGE = EV::ADNS
296 311
297PROTOTYPES: ENABLE 312PROTOTYPES: ENABLE
298 313
386 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; )
387 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 402 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
388 403
389 I_EV_API ("EV::ADNS"); 404 I_EV_API ("EV::ADNS");
390 405
391 ev_prepare_init (&prepare_ev, prepare_cb); ev_prepare_start (EV_DEFAULT_ &prepare_ev); 406 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0);
407
408 ev_prepare_init (&pw, prepare_cb);
409 pw.data = (void *)ads;
410 ev_prepare_start (EV_DEFAULT_ &pw);
392 ev_unref (); 411 ev_unref ();
393 412
413 ev_init (&iw, idle_cb); ev_set_priority (&iw, EV_MINPRI);
414 iw.data = (void *)ads;
394 ev_init (&tw, timer_cb); 415 ev_init (&tw, timer_cb);
395 416 tw.data = (void *)ads;
396 adns_init (&ads, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn | adns_if_noautosys, 0);
397} 417}
398 418
399void submit (char *owner, int type, int flags, SV *cb) 419void submit (char *owner, int type, int flags, SV *cb)
400 PPCODE: 420 PPCODE:
401{ 421{
416 SvCUR_set (csv, sizeof (struct ctx)); 436 SvCUR_set (csv, sizeof (struct ctx));
417 437
418 c->self = csv; 438 c->self = csv;
419 c->cb = newSVsv (cb); 439 c->cb = newSVsv (cb);
420 440
441 if (!ev_is_active (&iw))
442 ev_idle_start (EV_A_ &iw);
443
421 if (GIMME_V != G_VOID) 444 if (GIMME_V != G_VOID)
422 { 445 {
423 csv = sv_2mortal (newRV_inc (csv)); 446 csv = sv_2mortal (newRV_inc (csv));
424 sv_bless (csv, stash); 447 sv_bless (csv, stash);
425 XPUSHs (csv); 448 XPUSHs (csv);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines