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

Comparing EV/EV.xs (file contents):
Revision 1.83 by root, Thu Nov 29 17:28:13 2007 UTC vs.
Revision 1.92 by root, Thu Dec 20 08:18:54 2007 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define EV_PROTOTYPES 1 7#define EV_PROTOTYPES 1
8#define EV_H <ev.h>
8#include "EV/EVAPI.h" 9#include "EV/EVAPI.h"
9 10
10/* fix perl api breakage */ 11/* fix perl api breakage */
11#undef signal 12#undef signal
12#undef sigaction 13#undef sigaction
17# define NFDBITS PERL_NFDBITS 18# define NFDBITS PERL_NFDBITS
18# define fd_mask Perl_fd_mask 19# define fd_mask Perl_fd_mask
19#endif 20#endif
20/* due to bugs in OS X we have to use libev/ explicitly here */ 21/* due to bugs in OS X we have to use libev/ explicitly here */
21#include "libev/ev.c" 22#include "libev/ev.c"
22#include "event.c"
23
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 23
36#ifndef _WIN32 24#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); \
113} 101}
114 102
115///////////////////////////////////////////////////////////////////////////// 103/////////////////////////////////////////////////////////////////////////////
116// Event 104// Event
117 105
118static void e_cb (ev_watcher *w, int revents); 106static void e_cb (EV_P_ ev_watcher *w, int revents);
119 107
120static int 108static int
121sv_fileno (SV *fh) 109sv_fileno (SV *fh)
122{ 110{
123 SvGETMAGIC (fh); 111 SvGETMAGIC (fh);
144 132
145 w = (ev_watcher *)SvPVX (self); 133 w = (ev_watcher *)SvPVX (self);
146 134
147 ev_init (w, e_cb); 135 ev_init (w, e_cb);
148 136
137 w->loop = EV_DEFAULT;
149 w->flags = WFLAG_KEEPALIVE; 138 w->flags = WFLAG_KEEPALIVE;
150 w->data = 0; 139 w->data = 0;
151 w->fh = 0; 140 w->fh = 0;
152 w->cb_sv = newSVsv (cb_sv); 141 w->cb_sv = newSVsv (cb_sv);
153 w->self = self; 142 w->self = self;
183} 172}
184 173
185static SV *sv_events_cache; 174static SV *sv_events_cache;
186 175
187static void 176static void
188e_cb (ev_watcher *w, int revents) 177e_cb (EV_P_ ev_watcher *w, int revents)
189{ 178{
190 dSP; 179 dSP;
191 I32 mark = SP - PL_stack_base; 180 I32 mark = SP - PL_stack_base;
192 SV *sv_self, *sv_events; 181 SV *sv_self, *sv_events;
193 182
216 else 205 else
217 sv_events_cache = sv_events; 206 sv_events_cache = sv_events;
218 207
219 if (SvTRUE (ERRSV)) 208 if (SvTRUE (ERRSV))
220 { 209 {
210 SPAGAIN;
221 PUSHMARK (SP); 211 PUSHMARK (SP);
222 PUTBACK; 212 PUTBACK;
223 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);
224 } 214 }
225 215
255 else 245 else
256 sv_events_cache = sv_events; 246 sv_events_cache = sv_events;
257 247
258 if (SvTRUE (ERRSV)) 248 if (SvTRUE (ERRSV))
259 { 249 {
250 SPAGAIN;
260 PUSHMARK (SP); 251 PUSHMARK (SP);
261 PUTBACK; 252 PUTBACK;
262 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);
263 } 254 }
264 255
306 FREETMPS; 297 FREETMPS;
307 LEAVE; 298 LEAVE;
308 299
309 return retval; 300 return retval;
310} 301}
311
312/////////////////////////////////////////////////////////////////////////////
313// DNS
314
315#ifndef _WIN32
316static void
317dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
318{
319 dSP;
320 SV *cb = (SV *)arg;
321
322 ENTER;
323 SAVETMPS;
324 PUSHMARK (SP);
325 EXTEND (SP, count + 3);
326 PUSHs (sv_2mortal (newSViv (result)));
327
328 if (result == DNS_ERR_NONE && ttl >= 0)
329 {
330 int i;
331
332 PUSHs (sv_2mortal (newSViv (type)));
333 PUSHs (sv_2mortal (newSViv (ttl)));
334
335 for (i = 0; i < count; ++i)
336 switch (type)
337 {
338 case DNS_IPv6_AAAA:
339 PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
340 break;
341 case DNS_IPv4_A:
342 PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
343 break;
344 case DNS_PTR:
345 PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
346 break;
347 }
348 }
349
350 PUTBACK;
351 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
352
353 FREETMPS;
354
355 if (SvTRUE (ERRSV))
356 {
357 PUSHMARK (SP);
358 PUTBACK;
359 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
360 }
361
362 LEAVE;
363}
364#endif
365 302
366#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 303#define CHECK_REPEAT(repeat) if (repeat < 0.) \
367 croak (# repeat " value must be >= 0"); 304 croak (# repeat " value must be >= 0");
368 305
369#define CHECK_FD(fh,fd) if ((fd) < 0) \ 306#define CHECK_FD(fh,fd) if ((fd) < 0) \
429 stash_prepare = gv_stashpv ("EV::Prepare" , 1); 366 stash_prepare = gv_stashpv ("EV::Prepare" , 1);
430 stash_check = gv_stashpv ("EV::Check" , 1); 367 stash_check = gv_stashpv ("EV::Check" , 1);
431 stash_child = gv_stashpv ("EV::Child" , 1); 368 stash_child = gv_stashpv ("EV::Child" , 1);
432 stash_embed = gv_stashpv ("EV::Embed" , 1); 369 stash_embed = gv_stashpv ("EV::Embed" , 1);
433 stash_stat = gv_stashpv ("EV::Stat" , 1); 370 stash_stat = gv_stashpv ("EV::Stat" , 1);
371 stash_fork = gv_stashpv ("EV::Fork" , 1);
434 372
435 { 373 {
436 SV *sv = perl_get_sv ("EV::API", TRUE); 374 SV *sv = perl_get_sv ("EV::API", TRUE);
437 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 375 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
438 376
439 /* the poor man's shared library emulator */ 377 /* the poor man's shared library emulator */
440 evapi.ver = EV_API_VERSION; 378 evapi.ver = EV_API_VERSION;
441 evapi.rev = EV_API_REVISION; 379 evapi.rev = EV_API_REVISION;
442 evapi.sv_fileno = sv_fileno; 380 evapi.sv_fileno = sv_fileno;
443 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;
444 evapi.now = ev_now; 390 evapi.now = ev_now;
445 evapi.backend = ev_backend; 391 evapi.backend = ev_backend;
446 evapi.unloop = ev_unloop; 392 evapi.unloop = ev_unloop;
447 evapi.ref = ev_ref; 393 evapi.ref = ev_ref;
448 evapi.unref = ev_unref; 394 evapi.unref = ev_unref;
449 evapi.time = ev_time;
450 evapi.loop = ev_loop; 395 evapi.loop = ev_loop;
451 evapi.once = ev_once; 396 evapi.once = ev_once;
452 evapi.io_start = ev_io_start; 397 evapi.io_start = ev_io_start;
453 evapi.io_stop = ev_io_stop; 398 evapi.io_stop = ev_io_stop;
454 evapi.timer_start = ev_timer_start; 399 evapi.timer_start = ev_timer_start;
455 evapi.timer_stop = ev_timer_stop; 400 evapi.timer_stop = ev_timer_stop;
456 evapi.timer_again = ev_timer_again; 401 evapi.timer_again = ev_timer_again;
457 evapi.periodic_start = ev_periodic_start; 402 evapi.periodic_start = ev_periodic_start;
458 evapi.periodic_stop = ev_periodic_stop; 403 evapi.periodic_stop = ev_periodic_stop;
459 evapi.signal_start = ev_signal_start; 404 evapi.signal_start = ev_signal_start;
460 evapi.signal_stop = ev_signal_stop; 405 evapi.signal_stop = ev_signal_stop;
461 evapi.idle_start = ev_idle_start; 406 evapi.idle_start = ev_idle_start;
462 evapi.idle_stop = ev_idle_stop; 407 evapi.idle_stop = ev_idle_stop;
463 evapi.prepare_start = ev_prepare_start; 408 evapi.prepare_start = ev_prepare_start;
464 evapi.prepare_stop = ev_prepare_stop; 409 evapi.prepare_stop = ev_prepare_stop;
465 evapi.check_start = ev_check_start; 410 evapi.check_start = ev_check_start;
466 evapi.check_stop = ev_check_stop; 411 evapi.check_stop = ev_check_stop;
467 evapi.child_start = ev_child_start; 412 evapi.child_start = ev_child_start;
468 evapi.child_stop = ev_child_stop; 413 evapi.child_stop = ev_child_stop;
469 evapi.stat_start = ev_stat_start; 414 evapi.stat_start = ev_stat_start;
470 evapi.stat_stop = ev_stat_stop; 415 evapi.stat_stop = ev_stat_stop;
471 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;
472 424
473 sv_setiv (sv, (IV)&evapi); 425 sv_setiv (sv, (IV)&evapi);
474 SvREADONLY_on (sv); 426 SvREADONLY_on (sv);
475 } 427 }
476#ifndef _WIN32 428#ifndef _WIN32
477 pthread_atfork (0, 0, ev_default_fork); 429 pthread_atfork (0, 0, ev_default_fork);
478#endif 430#endif
479} 431}
480 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
481NV ev_now () 448NV ev_now ()
449 C_ARGS: evapi.default_loop
482 450
483unsigned int ev_backend () 451unsigned int ev_backend ()
452 C_ARGS: evapi.default_loop
484 453
485NV ev_time () 454unsigned int ev_loop_count ()
486 455 C_ARGS: evapi.default_loop
487unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
488 456
489void ev_loop (int flags = 0) 457void ev_loop (int flags = 0)
458 C_ARGS: evapi.default_loop, flags
490 459
491void 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}
492 474
493ev_io *io (SV *fh, int events, SV *cb) 475ev_io *io (SV *fh, int events, SV *cb)
494 ALIAS: 476 ALIAS:
495 io_ns = 1 477 io_ns = 1
496 CODE: 478 CODE:
578 ev_check_set (RETVAL); 560 ev_check_set (RETVAL);
579 if (!ix) START (check, RETVAL); 561 if (!ix) START (check, RETVAL);
580 OUTPUT: 562 OUTPUT:
581 RETVAL 563 RETVAL
582 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
583ev_child *child (int pid, SV *cb) 575ev_child *child (int pid, SV *cb)
584 ALIAS: 576 ALIAS:
585 child_ns = 1 577 child_ns = 1
586 CODE: 578 CODE:
587 RETVAL = e_new (sizeof (ev_child), cb); 579 RETVAL = e_new (sizeof (ev_child), cb);
602 RETVAL 594 RETVAL
603 595
604void once (SV *fh, int events, SV *timeout, SV *cb) 596void once (SV *fh, int events, SV *timeout, SV *cb)
605 CODE: 597 CODE:
606 ev_once ( 598 ev_once (
599 evapi.default_loop,
607 sv_fileno (fh), events, 600 sv_fileno (fh), events,
608 SvOK (timeout) ? SvNV (timeout) : -1., 601 SvOK (timeout) ? SvNV (timeout) : -1.,
609 e_once_cb, 602 e_once_cb,
610 newSVsv (cb) 603 newSVsv (cb)
611 ); 604 );
615MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ 608MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_
616 609
617int ev_is_active (ev_watcher *w) 610int ev_is_active (ev_watcher *w)
618 611
619int 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
620 622
621int keepalive (ev_watcher *w, int new_value = 0) 623int keepalive (ev_watcher *w, int new_value = 0)
622 CODE: 624 CODE:
623{ 625{
624 RETVAL = w->flags & WFLAG_KEEPALIVE; 626 RETVAL = w->flags & WFLAG_KEEPALIVE;
657 } 659 }
658} 660}
659 OUTPUT: 661 OUTPUT:
660 RETVAL 662 RETVAL
661 663
662void trigger (ev_watcher *w, int revents = EV_NONE)
663 CODE:
664 w->cb (w, revents);
665
666int priority (ev_watcher *w, int new_priority = 0) 664int priority (ev_watcher *w, int new_priority = 0)
667 CODE: 665 CODE:
668{ 666{
669 RETVAL = w->priority; 667 RETVAL = w->priority;
670 668
671 if (items > 1) 669 if (items > 1)
672 { 670 {
673 int active = ev_is_active (w); 671 int active = ev_is_active (w);
674
675 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
676 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
677 672
678 if (active) 673 if (active)
679 { 674 {
680 /* grrr. */ 675 /* grrr. */
681 PUSHMARK (SP); 676 PUSHMARK (SP);
682 XPUSHs (ST (0)); 677 XPUSHs (ST (0));
678 PUTBACK;
683 call_method ("stop", G_DISCARD | G_VOID); 679 call_method ("stop", G_DISCARD | G_VOID);
684 } 680 }
685 681
686 ev_set_priority (w, new_priority); 682 ev_set_priority (w, new_priority);
687 683
688 if (active) 684 if (active)
689 { 685 {
690 PUSHMARK (SP); 686 PUSHMARK (SP);
691 XPUSHs (ST (0)); 687 XPUSHs (ST (0));
688 PUTBACK;
692 call_method ("start", G_DISCARD | G_VOID); 689 call_method ("start", G_DISCARD | G_VOID);
693 } 690 }
694 } 691 }
695} 692}
696 OUTPUT: 693 OUTPUT:
806void ev_timer_again (ev_timer *w) 803void ev_timer_again (ev_timer *w)
807 INIT: 804 INIT:
808 CHECK_REPEAT (w->repeat); 805 CHECK_REPEAT (w->repeat);
809 CODE: 806 CODE:
810 REF (w); 807 REF (w);
811 ev_timer_again (w); 808 ev_timer_again (w->loop, w);
812 UNREF (w); 809 UNREF (w);
813 810
814void DESTROY (ev_timer *w) 811void DESTROY (ev_timer *w)
815 CODE: 812 CODE:
816 STOP (timer, w); 813 STOP (timer, w);
820 INIT: 817 INIT:
821 CHECK_REPEAT (repeat); 818 CHECK_REPEAT (repeat);
822 CODE: 819 CODE:
823 RESET (timer, w, (w, after, repeat)); 820 RESET (timer, w, (w, after, repeat));
824 821
822NV at (ev_timer *w)
823 CODE:
824 RETVAL = w->at;
825 OUTPUT:
826 RETVAL
827
825MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 828MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
826 829
827void ev_periodic_start (ev_periodic *w) 830void ev_periodic_start (ev_periodic *w)
828 INIT: 831 INIT:
829 CHECK_REPEAT (w->interval); 832 CHECK_REPEAT (w->interval);
835 STOP (periodic, w); 838 STOP (periodic, w);
836 839
837void ev_periodic_again (ev_periodic *w) 840void ev_periodic_again (ev_periodic *w)
838 CODE: 841 CODE:
839 REF (w); 842 REF (w);
840 ev_periodic_again (w); 843 ev_periodic_again (w->loop, w);
841 UNREF (w); 844 UNREF (w);
842 845
843void DESTROY (ev_periodic *w) 846void DESTROY (ev_periodic *w)
844 CODE: 847 CODE:
845 STOP (periodic, w); 848 STOP (periodic, w);
854 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 857 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
855 858
856 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));
857} 860}
858 861
862NV at (ev_periodic *w)
863 CODE:
864 RETVAL = w->at;
865 OUTPUT:
866 RETVAL
867
859MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 868MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
860 869
861void ev_idle_start (ev_idle *w) 870void ev_idle_start (ev_idle *w)
862 CODE: 871 CODE:
863 START (idle, w); 872 START (idle, w);
897 STOP (check, w); 906 STOP (check, w);
898 907
899void DESTROY (ev_check *w) 908void DESTROY (ev_check *w)
900 CODE: 909 CODE:
901 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);
902 e_destroy (w); 926 e_destroy (w);
903 927
904MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ 928MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_
905 929
906void ev_child_start (ev_child *w) 930void ev_child_start (ev_child *w)
995 PPCODE: 1019 PPCODE:
996{ 1020{
997 ev_statdata *s = ix ? &w->attr : &w->prev; 1021 ev_statdata *s = ix ? &w->attr : &w->prev;
998 1022
999 if (ix == 1) 1023 if (ix == 1)
1000 ev_stat_stat (w); 1024 ev_stat_stat (w->loop, w);
1001 else if (!s->st_nlink) 1025 else if (!s->st_nlink)
1002 errno = ENOENT; 1026 errno = ENOENT;
1003 1027
1004 PL_statcache.st_dev = s->st_nlink; 1028 PL_statcache.st_dev = s->st_nlink;
1005 PL_statcache.st_ino = s->st_ino; 1029 PL_statcache.st_ino = s->st_ino;
1031 PUSHs (sv_2mortal (newSVnv (s->st_ctime))); 1055 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1032 PUSHs (sv_2mortal (newSVuv (4096))); 1056 PUSHs (sv_2mortal (newSVuv (4096)));
1033 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 1057 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1034 } 1058 }
1035} 1059}
1036
1037#ifndef _WIN32
1038
1039MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
1040
1041BOOT:
1042{
1043 HV *stash = gv_stashpv ("EV::DNS", 1);
1044
1045 static const struct {
1046 const char *name;
1047 IV iv;
1048 } *civ, const_iv[] = {
1049# define const_iv(pfx, name) { # name, (IV) pfx ## name },
1050 const_iv (DNS_, ERR_NONE)
1051 const_iv (DNS_, ERR_FORMAT)
1052 const_iv (DNS_, ERR_SERVERFAILED)
1053 const_iv (DNS_, ERR_NOTEXIST)
1054 const_iv (DNS_, ERR_NOTIMPL)
1055 const_iv (DNS_, ERR_REFUSED)
1056 const_iv (DNS_, ERR_TRUNCATED)
1057 const_iv (DNS_, ERR_UNKNOWN)
1058 const_iv (DNS_, ERR_TIMEOUT)
1059 const_iv (DNS_, ERR_SHUTDOWN)
1060 const_iv (DNS_, IPv4_A)
1061 const_iv (DNS_, PTR)
1062 const_iv (DNS_, IPv6_AAAA)
1063 const_iv (DNS_, QUERY_NO_SEARCH)
1064 const_iv (DNS_, OPTION_SEARCH)
1065 const_iv (DNS_, OPTION_NAMESERVERS)
1066 const_iv (DNS_, OPTION_MISC)
1067 const_iv (DNS_, OPTIONS_ALL)
1068 const_iv (DNS_, NO_SEARCH)
1069 };
1070
1071 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1072 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1073}
1074
1075int evdns_init ()
1076
1077void evdns_shutdown (int fail_requests = 1)
1078
1079const char *evdns_err_to_string (int err)
1080
1081int evdns_nameserver_add (U32 address)
1082
1083int evdns_count_nameservers ()
1084
1085int evdns_clear_nameservers_and_suspend ()
1086
1087int evdns_resume ()
1088
1089int evdns_nameserver_ip_add (char *ip_as_string)
1090
1091int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
1092 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1093
1094int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
1095 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1096
1097int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
1098 ALIAS:
1099 evdns_resolve_reverse_ipv6 = 1
1100 CODE:
1101{
1102 STRLEN len;
1103 char *data = SvPVbyte (addr, len);
1104 if (len != (ix ? 16 : 4))
1105 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
1106
1107 RETVAL = ix
1108 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
1109 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
1110}
1111 OUTPUT:
1112 RETVAL
1113
1114int evdns_set_option (char *option, char *val, int flags)
1115
1116int evdns_resolv_conf_parse (int flags, const char *filename)
1117
1118#ifdef _WIN32
1119
1120int evdns_config_windows_nameservers ()
1121
1122#endif
1123
1124void evdns_search_clear ()
1125
1126void evdns_search_add (char *domain)
1127
1128void evdns_search_ndots_set (int ndots)
1129 1060
1130#if 0 1061#if 0
1131 1062
1132MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1063MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1133 1064
1167 1098
1168#void DESTROY (struct evhttp_request *req); 1099#void DESTROY (struct evhttp_request *req);
1169 1100
1170#endif 1101#endif
1171 1102
1172#endif
1173 1103
1174 1104
1175 1105
1176 1106
1177 1107

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines