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

Comparing EV/EV.xs (file contents):
Revision 1.80 by root, Tue Nov 27 07:27:10 2007 UTC vs.
Revision 1.91 by root, Thu Dec 20 07:12:57 2007 UTC

20/* due to bugs in OS X we have to use libev/ explicitly here */ 20/* due to bugs in OS X we have to use libev/ explicitly here */
21#include "libev/ev.c" 21#include "libev/ev.c"
22#include "event.c" 22#include "event.c"
23 23
24#ifndef _WIN32 24#ifndef _WIN32
25#define DNS_USE_GETTIMEOFDAY_FOR_ID 1
26#if !defined (WIN32) && !defined(__CYGWIN__)
27# define HAVE_STRUCT_IN6_ADDR 1
28#endif
29#undef HAVE_STRTOK_R
30#undef strtok_r
31#define strtok_r fake_strtok_r
32#include "evdns.h"
33#include "evdns.c"
34#endif
35
36#ifndef _WIN32
37# include <pthread.h> 25# include <pthread.h>
38#endif 26#endif
39 27
40#define WFLAG_KEEPALIVE 1 28#define WFLAG_KEEPALIVE 1
41 29
42#define UNREF(w) \ 30#define UNREF(w) \
43 if (!((w)->flags & WFLAG_KEEPALIVE) \ 31 if (!((w)->flags & WFLAG_KEEPALIVE) \
44 && !ev_is_active (w)) \ 32 && !ev_is_active (w)) \
45 ev_unref (); 33 ev_unref (w->loop);
46 34
47#define REF(w) \ 35#define REF(w) \
48 if (!((w)->flags & WFLAG_KEEPALIVE) \ 36 if (!((w)->flags & WFLAG_KEEPALIVE) \
49 && ev_is_active (w)) \ 37 && ev_is_active (w)) \
50 ev_ref (); 38 ev_ref (w->loop);
51 39
52#define START(type,w) \ 40#define START(type,w) \
53 do { \ 41 do { \
54 UNREF (w); \ 42 UNREF (w); \
55 ev_ ## type ## _start (w); \ 43 ev_ ## type ## _start (w->loop, w); \
56 } while (0) 44 } while (0)
57 45
58#define STOP(type,w) \ 46#define STOP(type,w) \
59 do { \ 47 do { \
60 REF (w); \ 48 REF (w); \
61 ev_ ## type ## _stop (w); \ 49 ev_ ## type ## _stop (w->loop, w); \
62 } while (0) 50 } while (0)
63 51
64#define RESET(type,w,seta) \ 52#define RESET(type,w,seta) \
65 do { \ 53 do { \
66 int active = ev_is_active (w); \ 54 int active = ev_is_active (w); \
77 *stash_watcher, 65 *stash_watcher,
78 *stash_io, 66 *stash_io,
79 *stash_timer, 67 *stash_timer,
80 *stash_periodic, 68 *stash_periodic,
81 *stash_signal, 69 *stash_signal,
70 *stash_child,
71 *stash_stat,
82 *stash_idle, 72 *stash_idle,
83 *stash_prepare, 73 *stash_prepare,
84 *stash_check, 74 *stash_check,
85 *stash_child,
86 *stash_embed, 75 *stash_embed,
87 *stash_stat; 76 *stash_fork;
88 77
89#ifndef SIG_SIZE 78#ifndef SIG_SIZE
90/* kudos to Slaven Rezic for the idea */ 79/* kudos to Slaven Rezic for the idea */
91static char sig_size [] = { SIG_NUM }; 80static char sig_size [] = { SIG_NUM };
92# define SIG_SIZE (sizeof (sig_size) + 1) 81# define SIG_SIZE (sizeof (sig_size) + 1)
112} 101}
113 102
114///////////////////////////////////////////////////////////////////////////// 103/////////////////////////////////////////////////////////////////////////////
115// Event 104// Event
116 105
117static void e_cb (ev_watcher *w, int revents); 106static void e_cb (EV_P_ ev_watcher *w, int revents);
118 107
119static int 108static int
120sv_fileno (SV *fh) 109sv_fileno (SV *fh)
121{ 110{
122 SvGETMAGIC (fh); 111 SvGETMAGIC (fh);
143 132
144 w = (ev_watcher *)SvPVX (self); 133 w = (ev_watcher *)SvPVX (self);
145 134
146 ev_init (w, e_cb); 135 ev_init (w, e_cb);
147 136
137 w->loop = EV_DEFAULT;
148 w->flags = WFLAG_KEEPALIVE; 138 w->flags = WFLAG_KEEPALIVE;
149 w->data = 0; 139 w->data = 0;
150 w->fh = 0; 140 w->fh = 0;
151 w->cb_sv = newSVsv (cb_sv); 141 w->cb_sv = newSVsv (cb_sv);
152 w->self = self; 142 w->self = self;
182} 172}
183 173
184static SV *sv_events_cache; 174static SV *sv_events_cache;
185 175
186static void 176static void
187e_cb (ev_watcher *w, int revents) 177e_cb (EV_P_ ev_watcher *w, int revents)
188{ 178{
189 dSP; 179 dSP;
190 I32 mark = SP - PL_stack_base; 180 I32 mark = SP - PL_stack_base;
191 SV *sv_self, *sv_events; 181 SV *sv_self, *sv_events;
192 182
215 else 205 else
216 sv_events_cache = sv_events; 206 sv_events_cache = sv_events;
217 207
218 if (SvTRUE (ERRSV)) 208 if (SvTRUE (ERRSV))
219 { 209 {
210 SPAGAIN;
220 PUSHMARK (SP); 211 PUSHMARK (SP);
221 PUTBACK; 212 PUTBACK;
222 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 213 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
223 } 214 }
224 215
254 else 245 else
255 sv_events_cache = sv_events; 246 sv_events_cache = sv_events;
256 247
257 if (SvTRUE (ERRSV)) 248 if (SvTRUE (ERRSV))
258 { 249 {
250 SPAGAIN;
259 PUSHMARK (SP); 251 PUSHMARK (SP);
260 PUTBACK; 252 PUTBACK;
261 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); 253 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
262 } 254 }
263 255
305 FREETMPS; 297 FREETMPS;
306 LEAVE; 298 LEAVE;
307 299
308 return retval; 300 return retval;
309} 301}
310
311/////////////////////////////////////////////////////////////////////////////
312// DNS
313
314#ifndef _WIN32
315static void
316dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
317{
318 dSP;
319 SV *cb = (SV *)arg;
320
321 ENTER;
322 SAVETMPS;
323 PUSHMARK (SP);
324 EXTEND (SP, count + 3);
325 PUSHs (sv_2mortal (newSViv (result)));
326
327 if (result == DNS_ERR_NONE && ttl >= 0)
328 {
329 int i;
330
331 PUSHs (sv_2mortal (newSViv (type)));
332 PUSHs (sv_2mortal (newSViv (ttl)));
333
334 for (i = 0; i < count; ++i)
335 switch (type)
336 {
337 case DNS_IPv6_AAAA:
338 PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
339 break;
340 case DNS_IPv4_A:
341 PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
342 break;
343 case DNS_PTR:
344 PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
345 break;
346 }
347 }
348
349 PUTBACK;
350 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
351
352 FREETMPS;
353
354 if (SvTRUE (ERRSV))
355 {
356 PUSHMARK (SP);
357 PUTBACK;
358 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
359 }
360
361 LEAVE;
362}
363#endif
364 302
365#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 303#define CHECK_REPEAT(repeat) if (repeat < 0.) \
366 croak (# repeat " value must be >= 0"); 304 croak (# repeat " value must be >= 0");
367 305
368#define CHECK_FD(fh,fd) if ((fd) < 0) \ 306#define CHECK_FD(fh,fd) if ((fd) < 0) \
411 const_iv (EV, BACKEND_KQUEUE) 349 const_iv (EV, BACKEND_KQUEUE)
412 const_iv (EV, BACKEND_DEVPOLL) 350 const_iv (EV, BACKEND_DEVPOLL)
413 const_iv (EV, BACKEND_PORT) 351 const_iv (EV, BACKEND_PORT)
414 const_iv (EV, FLAG_AUTO) 352 const_iv (EV, FLAG_AUTO)
415 const_iv (EV, FLAG_NOENV) 353 const_iv (EV, FLAG_NOENV)
354 const_iv (EV, FLAG_FORKCHECK)
416 }; 355 };
417 356
418 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 357 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
419 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 358 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
420 359
427 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 366 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
428 stash_check = gv_stashpv ("EV::Check" , 1); 367 stash_check = gv_stashpv ("EV::Check" , 1);
429 stash_child = gv_stashpv ("EV::Child" , 1); 368 stash_child = gv_stashpv ("EV::Child" , 1);
430 stash_embed = gv_stashpv ("EV::Embed" , 1); 369 stash_embed = gv_stashpv ("EV::Embed" , 1);
431 stash_stat = gv_stashpv ("EV::Stat" , 1); 370 stash_stat = gv_stashpv ("EV::Stat" , 1);
371 stash_fork = gv_stashpv ("EV::Fork" , 1);
432 372
433 { 373 {
434 SV *sv = perl_get_sv ("EV::API", TRUE); 374 SV *sv = perl_get_sv ("EV::API", TRUE);
435 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 375 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
436 376
437 /* the poor man's shared library emulator */ 377 /* the poor man's shared library emulator */
438 evapi.ver = EV_API_VERSION; 378 evapi.ver = EV_API_VERSION;
439 evapi.rev = EV_API_REVISION; 379 evapi.rev = EV_API_REVISION;
440 evapi.sv_fileno = sv_fileno; 380 evapi.sv_fileno = sv_fileno;
441 evapi.sv_signum = sv_signum; 381 evapi.sv_signum = sv_signum;
382 evapi.supported_backends = ev_supported_backends ();
383 evapi.recommended_backends = ev_recommended_backends ();
384 evapi.embeddable_backends = ev_embeddable_backends ();
385 evapi.time = ev_time;
386 evapi.loop_new = ev_loop_new;
387 evapi.loop_destroy = ev_loop_destroy;
388 evapi.loop_fork = ev_loop_fork;
389 evapi.loop_count = ev_loop_count;
442 evapi.now = ev_now; 390 evapi.now = ev_now;
443 evapi.backend = ev_backend; 391 evapi.backend = ev_backend;
444 evapi.unloop = ev_unloop; 392 evapi.unloop = ev_unloop;
445 evapi.ref = ev_ref; 393 evapi.ref = ev_ref;
446 evapi.unref = ev_unref; 394 evapi.unref = ev_unref;
447 evapi.time = ev_time;
448 evapi.loop = ev_loop; 395 evapi.loop = ev_loop;
449 evapi.once = ev_once; 396 evapi.once = ev_once;
450 evapi.io_start = ev_io_start; 397 evapi.io_start = ev_io_start;
451 evapi.io_stop = ev_io_stop; 398 evapi.io_stop = ev_io_stop;
452 evapi.timer_start = ev_timer_start; 399 evapi.timer_start = ev_timer_start;
453 evapi.timer_stop = ev_timer_stop; 400 evapi.timer_stop = ev_timer_stop;
454 evapi.timer_again = ev_timer_again; 401 evapi.timer_again = ev_timer_again;
455 evapi.periodic_start = ev_periodic_start; 402 evapi.periodic_start = ev_periodic_start;
456 evapi.periodic_stop = ev_periodic_stop; 403 evapi.periodic_stop = ev_periodic_stop;
457 evapi.signal_start = ev_signal_start; 404 evapi.signal_start = ev_signal_start;
458 evapi.signal_stop = ev_signal_stop; 405 evapi.signal_stop = ev_signal_stop;
459 evapi.idle_start = ev_idle_start; 406 evapi.idle_start = ev_idle_start;
460 evapi.idle_stop = ev_idle_stop; 407 evapi.idle_stop = ev_idle_stop;
461 evapi.prepare_start = ev_prepare_start; 408 evapi.prepare_start = ev_prepare_start;
462 evapi.prepare_stop = ev_prepare_stop; 409 evapi.prepare_stop = ev_prepare_stop;
463 evapi.check_start = ev_check_start; 410 evapi.check_start = ev_check_start;
464 evapi.check_stop = ev_check_stop; 411 evapi.check_stop = ev_check_stop;
465 evapi.child_start = ev_child_start; 412 evapi.child_start = ev_child_start;
466 evapi.child_stop = ev_child_stop; 413 evapi.child_stop = ev_child_stop;
467 evapi.stat_start = ev_stat_start; 414 evapi.stat_start = ev_stat_start;
468 evapi.stat_stop = ev_stat_stop; 415 evapi.stat_stop = ev_stat_stop;
469 evapi.stat_stat = ev_stat_stat; 416 evapi.stat_stat = ev_stat_stat;
417 evapi.embed_start = ev_embed_start;
418 evapi.embed_stop = ev_embed_stop;
419 evapi.embed_sweep = ev_embed_sweep;
420 evapi.fork_start = ev_fork_start;
421 evapi.fork_stop = ev_fork_stop;
422 evapi.clear_pending = ev_clear_pending;
423 evapi.invoke = ev_invoke;
470 424
471 sv_setiv (sv, (IV)&evapi); 425 sv_setiv (sv, (IV)&evapi);
472 SvREADONLY_on (sv); 426 SvREADONLY_on (sv);
473 } 427 }
474#ifndef _WIN32 428#ifndef _WIN32
475 pthread_atfork (0, 0, ev_default_fork); 429 pthread_atfork (0, 0, ev_default_fork);
476#endif 430#endif
477} 431}
478 432
433SV *ev_default_loop (unsigned int flags = ev_supported_backends ())
434 CODE:
435{
436 evapi.default_loop = ev_default_loop (flags);
437 if (!evapi.default_loop)
438 XSRETURN_UNDEF;
439
440 RETVAL = sv_bless (newRV_noinc (newSViv (PTR2IV (ev_default_loop (flags)))),
441 gv_stashpv ("EV::Loop::Default", 1));
442}
443 OUTPUT:
444 RETVAL
445
446NV ev_time ()
447
479NV ev_now () 448NV ev_now ()
449 C_ARGS: evapi.default_loop
480 450
481unsigned int ev_backend () 451unsigned int ev_backend ()
452 C_ARGS: evapi.default_loop
482 453
483NV ev_time () 454unsigned int ev_loop_count ()
484 455 C_ARGS: evapi.default_loop
485unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
486 456
487void ev_loop (int flags = 0) 457void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags
488 459
489void ev_unloop (int how = 1) 460void ev_unloop (int how = 1)
461 C_ARGS: evapi.default_loop, how
462
463void ev_feed_fd_event (int fd, int revents = EV_NONE)
464 C_ARGS: evapi.default_loop, fd, revents
465
466void ev_feed_signal_event (SV *signal)
467 CODE:
468{
469 Signal signum = sv_signum (signal);
470 CHECK_SIG (signal, signum);
471
472 ev_feed_signal_event (evapi.default_loop, signum);
473}
490 474
491ev_io *io (SV *fh, int events, SV *cb) 475ev_io *io (SV *fh, int events, SV *cb)
492 ALIAS: 476 ALIAS:
493 io_ns = 1 477 io_ns = 1
494 CODE: 478 CODE:
576 ev_check_set (RETVAL); 560 ev_check_set (RETVAL);
577 if (!ix) START (check, RETVAL); 561 if (!ix) START (check, RETVAL);
578 OUTPUT: 562 OUTPUT:
579 RETVAL 563 RETVAL
580 564
565ev_fork *fork (SV *cb)
566 ALIAS:
567 fork_ns = 1
568 CODE:
569 RETVAL = e_new (sizeof (ev_fork), cb);
570 ev_fork_set (RETVAL);
571 if (!ix) START (fork, RETVAL);
572 OUTPUT:
573 RETVAL
574
581ev_child *child (int pid, SV *cb) 575ev_child *child (int pid, SV *cb)
582 ALIAS: 576 ALIAS:
583 child_ns = 1 577 child_ns = 1
584 CODE: 578 CODE:
585 RETVAL = e_new (sizeof (ev_child), cb); 579 RETVAL = e_new (sizeof (ev_child), cb);
600 RETVAL 594 RETVAL
601 595
602void once (SV *fh, int events, SV *timeout, SV *cb) 596void once (SV *fh, int events, SV *timeout, SV *cb)
603 CODE: 597 CODE:
604 ev_once ( 598 ev_once (
599 evapi.default_loop,
605 sv_fileno (fh), events, 600 sv_fileno (fh), events,
606 SvOK (timeout) ? SvNV (timeout) : -1., 601 SvOK (timeout) ? SvNV (timeout) : -1.,
607 e_once_cb, 602 e_once_cb,
608 newSVsv (cb) 603 newSVsv (cb)
609 ); 604 );
613MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 608MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
614 609
615int ev_is_active (ev_watcher *w) 610int ev_is_active (ev_watcher *w)
616 611
617int ev_is_pending (ev_watcher *w) 612int ev_is_pending (ev_watcher *w)
613
614void ev_invoke (ev_watcher *w, int revents = EV_NONE)
615 C_ARGS: w->loop, w, revents
616
617int ev_clear_pending (ev_watcher *w)
618 C_ARGS: w->loop, w
619
620void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
621 C_ARGS: w->loop, w, revents
618 622
619int keepalive (ev_watcher *w, int new_value = 0) 623int keepalive (ev_watcher *w, int new_value = 0)
620 CODE: 624 CODE:
621{ 625{
622 RETVAL = w->flags & WFLAG_KEEPALIVE; 626 RETVAL = w->flags & WFLAG_KEEPALIVE;
655 } 659 }
656} 660}
657 OUTPUT: 661 OUTPUT:
658 RETVAL 662 RETVAL
659 663
660void trigger (ev_watcher *w, int revents = EV_NONE)
661 CODE:
662 w->cb (w, revents);
663
664int priority (ev_watcher *w, int new_priority = 0) 664int priority (ev_watcher *w, int new_priority = 0)
665 CODE: 665 CODE:
666{ 666{
667 RETVAL = w->priority; 667 RETVAL = w->priority;
668 668
669 if (items > 1) 669 if (items > 1)
670 { 670 {
671 int active = ev_is_active (w); 671 int active = ev_is_active (w);
672
673 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
674 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
675 672
676 if (active) 673 if (active)
677 { 674 {
678 /* grrr. */ 675 /* grrr. */
679 PUSHMARK (SP); 676 PUSHMARK (SP);
680 XPUSHs (ST (0)); 677 XPUSHs (ST (0));
678 PUTBACK;
681 call_method ("stop", G_DISCARD | G_VOID); 679 call_method ("stop", G_DISCARD | G_VOID);
682 } 680 }
683 681
684 ev_set_priority (w, new_priority); 682 ev_set_priority (w, new_priority);
685 683
686 if (active) 684 if (active)
687 { 685 {
688 PUSHMARK (SP); 686 PUSHMARK (SP);
689 XPUSHs (ST (0)); 687 XPUSHs (ST (0));
688 PUTBACK;
690 call_method ("start", G_DISCARD | G_VOID); 689 call_method ("start", G_DISCARD | G_VOID);
691 } 690 }
692 } 691 }
693} 692}
694 OUTPUT: 693 OUTPUT:
804void ev_timer_again (ev_timer *w) 803void ev_timer_again (ev_timer *w)
805 INIT: 804 INIT:
806 CHECK_REPEAT (w->repeat); 805 CHECK_REPEAT (w->repeat);
807 CODE: 806 CODE:
808 REF (w); 807 REF (w);
809 ev_timer_again (w); 808 ev_timer_again (w->loop, w);
810 UNREF (w); 809 UNREF (w);
811 810
812void DESTROY (ev_timer *w) 811void DESTROY (ev_timer *w)
813 CODE: 812 CODE:
814 STOP (timer, w); 813 STOP (timer, w);
818 INIT: 817 INIT:
819 CHECK_REPEAT (repeat); 818 CHECK_REPEAT (repeat);
820 CODE: 819 CODE:
821 RESET (timer, w, (w, after, repeat)); 820 RESET (timer, w, (w, after, repeat));
822 821
822NV at (ev_timer *w)
823 CODE:
824 RETVAL = w->at;
825 OUTPUT:
826 RETVAL
827
823MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 828MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
824 829
825void ev_periodic_start (ev_periodic *w) 830void ev_periodic_start (ev_periodic *w)
826 INIT: 831 INIT:
827 CHECK_REPEAT (w->interval); 832 CHECK_REPEAT (w->interval);
833 STOP (periodic, w); 838 STOP (periodic, w);
834 839
835void ev_periodic_again (ev_periodic *w) 840void ev_periodic_again (ev_periodic *w)
836 CODE: 841 CODE:
837 REF (w); 842 REF (w);
838 ev_periodic_again (w); 843 ev_periodic_again (w->loop, w);
839 UNREF (w); 844 UNREF (w);
840 845
841void DESTROY (ev_periodic *w) 846void DESTROY (ev_periodic *w)
842 CODE: 847 CODE:
843 STOP (periodic, w); 848 STOP (periodic, w);
852 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 857 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
853 858
854 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 859 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
855} 860}
856 861
862NV at (ev_periodic *w)
863 CODE:
864 RETVAL = w->at;
865 OUTPUT:
866 RETVAL
867
857MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 868MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
858 869
859void ev_idle_start (ev_idle *w) 870void ev_idle_start (ev_idle *w)
860 CODE: 871 CODE:
861 START (idle, w); 872 START (idle, w);
895 STOP (check, w); 906 STOP (check, w);
896 907
897void DESTROY (ev_check *w) 908void DESTROY (ev_check *w)
898 CODE: 909 CODE:
899 STOP (check, w); 910 STOP (check, w);
911 e_destroy (w);
912
913MODULE = EV PACKAGE = EV::Fork PREFIX = ev_fork_
914
915void ev_fork_start (ev_fork *w)
916 CODE:
917 START (fork, w);
918
919void ev_fork_stop (ev_fork *w)
920 CODE:
921 STOP (fork, w);
922
923void DESTROY (ev_fork *w)
924 CODE:
925 STOP (fork, w);
900 e_destroy (w); 926 e_destroy (w);
901 927
902MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 928MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
903 929
904void ev_child_start (ev_child *w) 930void ev_child_start (ev_child *w)
984 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); 1010 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval));
985} 1011}
986 OUTPUT: 1012 OUTPUT:
987 RETVAL 1013 RETVAL
988 1014
989#ifndef _WIN32 1015void prev (ev_stat *w)
990
991MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
992
993BOOT:
994{
995 HV *stash = gv_stashpv ("EV::DNS", 1);
996
997 static const struct {
998 const char *name;
999 IV iv;
1000 } *civ, const_iv[] = {
1001# define const_iv(pfx, name) { # name, (IV) pfx ## name },
1002 const_iv (DNS_, ERR_NONE)
1003 const_iv (DNS_, ERR_FORMAT)
1004 const_iv (DNS_, ERR_SERVERFAILED)
1005 const_iv (DNS_, ERR_NOTEXIST)
1006 const_iv (DNS_, ERR_NOTIMPL)
1007 const_iv (DNS_, ERR_REFUSED)
1008 const_iv (DNS_, ERR_TRUNCATED)
1009 const_iv (DNS_, ERR_UNKNOWN)
1010 const_iv (DNS_, ERR_TIMEOUT)
1011 const_iv (DNS_, ERR_SHUTDOWN)
1012 const_iv (DNS_, IPv4_A)
1013 const_iv (DNS_, PTR)
1014 const_iv (DNS_, IPv6_AAAA)
1015 const_iv (DNS_, QUERY_NO_SEARCH)
1016 const_iv (DNS_, OPTION_SEARCH)
1017 const_iv (DNS_, OPTION_NAMESERVERS)
1018 const_iv (DNS_, OPTION_MISC)
1019 const_iv (DNS_, OPTIONS_ALL)
1020 const_iv (DNS_, NO_SEARCH)
1021 };
1022
1023 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1024 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1025}
1026
1027int evdns_init ()
1028
1029void evdns_shutdown (int fail_requests = 1)
1030
1031const char *evdns_err_to_string (int err)
1032
1033int evdns_nameserver_add (U32 address)
1034
1035int evdns_count_nameservers ()
1036
1037int evdns_clear_nameservers_and_suspend ()
1038
1039int evdns_resume ()
1040
1041int evdns_nameserver_ip_add (char *ip_as_string)
1042
1043int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
1044 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1045
1046int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
1047 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1048
1049int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
1050 ALIAS: 1016 ALIAS:
1051 evdns_resolve_reverse_ipv6 = 1 1017 stat = 1
1052 CODE: 1018 attr = 2
1019 PPCODE:
1053{ 1020{
1054 STRLEN len; 1021 ev_statdata *s = ix ? &w->attr : &w->prev;
1055 char *data = SvPVbyte (addr, len);
1056 if (len != (ix ? 16 : 4))
1057 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
1058 1022
1059 RETVAL = ix 1023 if (ix == 1)
1060 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) 1024 ev_stat_stat (w->loop, w);
1061 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); 1025 else if (!s->st_nlink)
1062} 1026 errno = ENOENT;
1063 OUTPUT:
1064 RETVAL
1065 1027
1066int evdns_set_option (char *option, char *val, int flags) 1028 PL_statcache.st_dev = s->st_nlink;
1029 PL_statcache.st_ino = s->st_ino;
1030 PL_statcache.st_mode = s->st_mode;
1031 PL_statcache.st_nlink = s->st_nlink;
1032 PL_statcache.st_uid = s->st_uid;
1033 PL_statcache.st_gid = s->st_gid;
1034 PL_statcache.st_rdev = s->st_rdev;
1035 PL_statcache.st_size = s->st_size;
1036 PL_statcache.st_atime = s->st_atime;
1037 PL_statcache.st_mtime = s->st_mtime;
1038 PL_statcache.st_ctime = s->st_ctime;
1067 1039
1068int evdns_resolv_conf_parse (int flags, const char *filename) 1040 if (GIMME_V == G_SCALAR)
1069 1041 XPUSHs (boolSV (s->st_nlink));
1070#ifdef _WIN32 1042 else if (GIMME_V == G_ARRAY && s->st_nlink)
1071 1043 {
1072int evdns_config_windows_nameservers () 1044 EXTEND (SP, 13);
1073 1045 PUSHs (sv_2mortal (newSViv (s->st_dev)));
1074#endif 1046 PUSHs (sv_2mortal (newSViv (s->st_ino)));
1075 1047 PUSHs (sv_2mortal (newSVuv (s->st_mode)));
1076void evdns_search_clear () 1048 PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
1077 1049 PUSHs (sv_2mortal (newSViv (s->st_uid)));
1078void evdns_search_add (char *domain) 1050 PUSHs (sv_2mortal (newSViv (s->st_gid)));
1079 1051 PUSHs (sv_2mortal (newSViv (s->st_rdev)));
1080void evdns_search_ndots_set (int ndots) 1052 PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
1053 PUSHs (sv_2mortal (newSVnv (s->st_atime)));
1054 PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
1055 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1056 PUSHs (sv_2mortal (newSVuv (4096)));
1057 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1058 }
1059}
1081 1060
1082#if 0 1061#if 0
1083 1062
1084MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1063MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1085 1064
1119 1098
1120#void DESTROY (struct evhttp_request *req); 1099#void DESTROY (struct evhttp_request *req);
1121 1100
1122#endif 1101#endif
1123 1102
1124#endif
1125 1103
1126 1104
1127 1105
1128 1106
1129 1107

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines