… | |
… | |
18 | # define fd_mask Perl_fd_mask |
18 | # define fd_mask Perl_fd_mask |
19 | #endif |
19 | #endif |
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 | |
|
|
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 | |
… | |
… | |
216 | else |
204 | else |
217 | sv_events_cache = sv_events; |
205 | sv_events_cache = sv_events; |
218 | |
206 | |
219 | if (SvTRUE (ERRSV)) |
207 | if (SvTRUE (ERRSV)) |
220 | { |
208 | { |
|
|
209 | SPAGAIN; |
221 | PUSHMARK (SP); |
210 | PUSHMARK (SP); |
222 | PUTBACK; |
211 | PUTBACK; |
223 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
212 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
224 | } |
213 | } |
225 | |
214 | |
… | |
… | |
255 | else |
244 | else |
256 | sv_events_cache = sv_events; |
245 | sv_events_cache = sv_events; |
257 | |
246 | |
258 | if (SvTRUE (ERRSV)) |
247 | if (SvTRUE (ERRSV)) |
259 | { |
248 | { |
|
|
249 | SPAGAIN; |
260 | PUSHMARK (SP); |
250 | PUSHMARK (SP); |
261 | PUTBACK; |
251 | PUTBACK; |
262 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
252 | call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR); |
263 | } |
253 | } |
264 | |
254 | |
… | |
… | |
306 | FREETMPS; |
296 | FREETMPS; |
307 | LEAVE; |
297 | LEAVE; |
308 | |
298 | |
309 | return retval; |
299 | return retval; |
310 | } |
300 | } |
311 | |
|
|
312 | ///////////////////////////////////////////////////////////////////////////// |
|
|
313 | // DNS |
|
|
314 | |
|
|
315 | #ifndef _WIN32 |
|
|
316 | static void |
|
|
317 | dns_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 | |
301 | |
366 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
302 | #define CHECK_REPEAT(repeat) if (repeat < 0.) \ |
367 | croak (# repeat " value must be >= 0"); |
303 | croak (# repeat " value must be >= 0"); |
368 | |
304 | |
369 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
305 | #define CHECK_FD(fh,fd) if ((fd) < 0) \ |
… | |
… | |
412 | const_iv (EV, BACKEND_KQUEUE) |
348 | const_iv (EV, BACKEND_KQUEUE) |
413 | const_iv (EV, BACKEND_DEVPOLL) |
349 | const_iv (EV, BACKEND_DEVPOLL) |
414 | const_iv (EV, BACKEND_PORT) |
350 | const_iv (EV, BACKEND_PORT) |
415 | const_iv (EV, FLAG_AUTO) |
351 | const_iv (EV, FLAG_AUTO) |
416 | const_iv (EV, FLAG_NOENV) |
352 | const_iv (EV, FLAG_NOENV) |
|
|
353 | const_iv (EV, FLAG_FORKCHECK) |
417 | }; |
354 | }; |
418 | |
355 | |
419 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
356 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
420 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
357 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
421 | |
358 | |
… | |
… | |
466 | evapi.child_start = ev_child_start; |
403 | evapi.child_start = ev_child_start; |
467 | evapi.child_stop = ev_child_stop; |
404 | evapi.child_stop = ev_child_stop; |
468 | evapi.stat_start = ev_stat_start; |
405 | evapi.stat_start = ev_stat_start; |
469 | evapi.stat_stop = ev_stat_stop; |
406 | evapi.stat_stop = ev_stat_stop; |
470 | evapi.stat_stat = ev_stat_stat; |
407 | evapi.stat_stat = ev_stat_stat; |
|
|
408 | evapi.clear_pending = ev_clear_pending; |
|
|
409 | evapi.invoke = ev_invoke; |
471 | |
410 | |
472 | sv_setiv (sv, (IV)&evapi); |
411 | sv_setiv (sv, (IV)&evapi); |
473 | SvREADONLY_on (sv); |
412 | SvREADONLY_on (sv); |
474 | } |
413 | } |
475 | #ifndef _WIN32 |
414 | #ifndef _WIN32 |
… | |
… | |
483 | |
422 | |
484 | NV ev_time () |
423 | NV ev_time () |
485 | |
424 | |
486 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
425 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
487 | |
426 | |
|
|
427 | unsigned int ev_loop_count () |
|
|
428 | |
488 | void ev_loop (int flags = 0) |
429 | void ev_loop (int flags = 0) |
489 | |
430 | |
490 | void ev_unloop (int how = 1) |
431 | void ev_unloop (int how = 1) |
|
|
432 | |
|
|
433 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
|
|
434 | |
|
|
435 | void ev_feed_signal_event (SV *signal) |
|
|
436 | CODE: |
|
|
437 | { |
|
|
438 | Signal signum = sv_signum (signal); |
|
|
439 | CHECK_SIG (signal, signum); |
|
|
440 | |
|
|
441 | ev_feed_signal_event (EV_DEFAULT_ signum); |
|
|
442 | } |
491 | |
443 | |
492 | ev_io *io (SV *fh, int events, SV *cb) |
444 | ev_io *io (SV *fh, int events, SV *cb) |
493 | ALIAS: |
445 | ALIAS: |
494 | io_ns = 1 |
446 | io_ns = 1 |
495 | CODE: |
447 | CODE: |
… | |
… | |
615 | |
567 | |
616 | int ev_is_active (ev_watcher *w) |
568 | int ev_is_active (ev_watcher *w) |
617 | |
569 | |
618 | int ev_is_pending (ev_watcher *w) |
570 | int ev_is_pending (ev_watcher *w) |
619 | |
571 | |
|
|
572 | void ev_invoke (ev_watcher *w, int revents = EV_NONE) |
|
|
573 | |
|
|
574 | int ev_clear_pending (ev_watcher *w) |
|
|
575 | |
|
|
576 | void ev_feed_event (ev_watcher *w, int revents = EV_NONE) |
|
|
577 | |
620 | int keepalive (ev_watcher *w, int new_value = 0) |
578 | int keepalive (ev_watcher *w, int new_value = 0) |
621 | CODE: |
579 | CODE: |
622 | { |
580 | { |
623 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
581 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
624 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
582 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
… | |
… | |
656 | } |
614 | } |
657 | } |
615 | } |
658 | OUTPUT: |
616 | OUTPUT: |
659 | RETVAL |
617 | RETVAL |
660 | |
618 | |
661 | void trigger (ev_watcher *w, int revents = EV_NONE) |
|
|
662 | CODE: |
|
|
663 | w->cb (w, revents); |
|
|
664 | |
|
|
665 | int priority (ev_watcher *w, int new_priority = 0) |
619 | int priority (ev_watcher *w, int new_priority = 0) |
666 | CODE: |
620 | CODE: |
667 | { |
621 | { |
668 | RETVAL = w->priority; |
622 | RETVAL = w->priority; |
669 | |
623 | |
670 | if (items > 1) |
624 | if (items > 1) |
671 | { |
625 | { |
672 | int active = ev_is_active (w); |
626 | int active = ev_is_active (w); |
673 | |
|
|
674 | if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI) |
|
|
675 | croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI); |
|
|
676 | |
627 | |
677 | if (active) |
628 | if (active) |
678 | { |
629 | { |
679 | /* grrr. */ |
630 | /* grrr. */ |
680 | PUSHMARK (SP); |
631 | PUSHMARK (SP); |
681 | XPUSHs (ST (0)); |
632 | XPUSHs (ST (0)); |
|
|
633 | PUTBACK; |
682 | call_method ("stop", G_DISCARD | G_VOID); |
634 | call_method ("stop", G_DISCARD | G_VOID); |
683 | } |
635 | } |
684 | |
636 | |
685 | ev_set_priority (w, new_priority); |
637 | ev_set_priority (w, new_priority); |
686 | |
638 | |
687 | if (active) |
639 | if (active) |
688 | { |
640 | { |
689 | PUSHMARK (SP); |
641 | PUSHMARK (SP); |
690 | XPUSHs (ST (0)); |
642 | XPUSHs (ST (0)); |
|
|
643 | PUTBACK; |
691 | call_method ("start", G_DISCARD | G_VOID); |
644 | call_method ("start", G_DISCARD | G_VOID); |
692 | } |
645 | } |
693 | } |
646 | } |
694 | } |
647 | } |
695 | OUTPUT: |
648 | OUTPUT: |
… | |
… | |
819 | INIT: |
772 | INIT: |
820 | CHECK_REPEAT (repeat); |
773 | CHECK_REPEAT (repeat); |
821 | CODE: |
774 | CODE: |
822 | RESET (timer, w, (w, after, repeat)); |
775 | RESET (timer, w, (w, after, repeat)); |
823 | |
776 | |
|
|
777 | NV at (ev_timer *w) |
|
|
778 | CODE: |
|
|
779 | RETVAL = w->at; |
|
|
780 | OUTPUT: |
|
|
781 | RETVAL |
|
|
782 | |
824 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
783 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
825 | |
784 | |
826 | void ev_periodic_start (ev_periodic *w) |
785 | void ev_periodic_start (ev_periodic *w) |
827 | INIT: |
786 | INIT: |
828 | CHECK_REPEAT (w->interval); |
787 | CHECK_REPEAT (w->interval); |
… | |
… | |
852 | SvREFCNT_dec (w->fh); |
811 | SvREFCNT_dec (w->fh); |
853 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
812 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
854 | |
813 | |
855 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
814 | RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); |
856 | } |
815 | } |
|
|
816 | |
|
|
817 | NV at (ev_periodic *w) |
|
|
818 | CODE: |
|
|
819 | RETVAL = w->at; |
|
|
820 | OUTPUT: |
|
|
821 | RETVAL |
857 | |
822 | |
858 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
823 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
859 | |
824 | |
860 | void ev_idle_start (ev_idle *w) |
825 | void ev_idle_start (ev_idle *w) |
861 | CODE: |
826 | CODE: |
… | |
… | |
1030 | PUSHs (sv_2mortal (newSVnv (s->st_ctime))); |
995 | PUSHs (sv_2mortal (newSVnv (s->st_ctime))); |
1031 | PUSHs (sv_2mortal (newSVuv (4096))); |
996 | PUSHs (sv_2mortal (newSVuv (4096))); |
1032 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
997 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
1033 | } |
998 | } |
1034 | } |
999 | } |
1035 | |
|
|
1036 | #ifndef _WIN32 |
|
|
1037 | |
|
|
1038 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
|
|
1039 | |
|
|
1040 | BOOT: |
|
|
1041 | { |
|
|
1042 | HV *stash = gv_stashpv ("EV::DNS", 1); |
|
|
1043 | |
|
|
1044 | static const struct { |
|
|
1045 | const char *name; |
|
|
1046 | IV iv; |
|
|
1047 | } *civ, const_iv[] = { |
|
|
1048 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
1049 | const_iv (DNS_, ERR_NONE) |
|
|
1050 | const_iv (DNS_, ERR_FORMAT) |
|
|
1051 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
1052 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
1053 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
1054 | const_iv (DNS_, ERR_REFUSED) |
|
|
1055 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
1056 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
1057 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
1058 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
1059 | const_iv (DNS_, IPv4_A) |
|
|
1060 | const_iv (DNS_, PTR) |
|
|
1061 | const_iv (DNS_, IPv6_AAAA) |
|
|
1062 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
1063 | const_iv (DNS_, OPTION_SEARCH) |
|
|
1064 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
1065 | const_iv (DNS_, OPTION_MISC) |
|
|
1066 | const_iv (DNS_, OPTIONS_ALL) |
|
|
1067 | const_iv (DNS_, NO_SEARCH) |
|
|
1068 | }; |
|
|
1069 | |
|
|
1070 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
1071 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
1072 | } |
|
|
1073 | |
|
|
1074 | int evdns_init () |
|
|
1075 | |
|
|
1076 | void evdns_shutdown (int fail_requests = 1) |
|
|
1077 | |
|
|
1078 | const char *evdns_err_to_string (int err) |
|
|
1079 | |
|
|
1080 | int evdns_nameserver_add (U32 address) |
|
|
1081 | |
|
|
1082 | int evdns_count_nameservers () |
|
|
1083 | |
|
|
1084 | int evdns_clear_nameservers_and_suspend () |
|
|
1085 | |
|
|
1086 | int evdns_resume () |
|
|
1087 | |
|
|
1088 | int evdns_nameserver_ip_add (char *ip_as_string) |
|
|
1089 | |
|
|
1090 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
|
|
1091 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1092 | |
|
|
1093 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
1094 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1095 | |
|
|
1096 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
1097 | ALIAS: |
|
|
1098 | evdns_resolve_reverse_ipv6 = 1 |
|
|
1099 | CODE: |
|
|
1100 | { |
|
|
1101 | STRLEN len; |
|
|
1102 | char *data = SvPVbyte (addr, len); |
|
|
1103 | if (len != (ix ? 16 : 4)) |
|
|
1104 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
1105 | |
|
|
1106 | RETVAL = ix |
|
|
1107 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
|
|
1108 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
|
|
1109 | } |
|
|
1110 | OUTPUT: |
|
|
1111 | RETVAL |
|
|
1112 | |
|
|
1113 | int evdns_set_option (char *option, char *val, int flags) |
|
|
1114 | |
|
|
1115 | int evdns_resolv_conf_parse (int flags, const char *filename) |
|
|
1116 | |
|
|
1117 | #ifdef _WIN32 |
|
|
1118 | |
|
|
1119 | int evdns_config_windows_nameservers () |
|
|
1120 | |
|
|
1121 | #endif |
|
|
1122 | |
|
|
1123 | void evdns_search_clear () |
|
|
1124 | |
|
|
1125 | void evdns_search_add (char *domain) |
|
|
1126 | |
|
|
1127 | void evdns_search_ndots_set (int ndots) |
|
|
1128 | |
1000 | |
1129 | #if 0 |
1001 | #if 0 |
1130 | |
1002 | |
1131 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1003 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1132 | |
1004 | |
… | |
… | |
1166 | |
1038 | |
1167 | #void DESTROY (struct evhttp_request *req); |
1039 | #void DESTROY (struct evhttp_request *req); |
1168 | |
1040 | |
1169 | #endif |
1041 | #endif |
1170 | |
1042 | |
1171 | #endif |
|
|
1172 | |
1043 | |
1173 | |
1044 | |
1174 | |
1045 | |
1175 | |
1046 | |
1176 | |
1047 | |