… | |
… | |
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 | |
… | |
… | |
483 | |
420 | |
484 | NV ev_time () |
421 | NV ev_time () |
485 | |
422 | |
486 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
423 | unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) |
487 | |
424 | |
|
|
425 | unsigned int ev_loop_count () |
|
|
426 | |
488 | void ev_loop (int flags = 0) |
427 | void ev_loop (int flags = 0) |
489 | |
428 | |
490 | void ev_unloop (int how = 1) |
429 | void ev_unloop (int how = 1) |
491 | |
430 | |
492 | ev_io *io (SV *fh, int events, SV *cb) |
431 | ev_io *io (SV *fh, int events, SV *cb) |
… | |
… | |
985 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
924 | RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); |
986 | } |
925 | } |
987 | OUTPUT: |
926 | OUTPUT: |
988 | RETVAL |
927 | RETVAL |
989 | |
928 | |
990 | #ifndef _WIN32 |
929 | void prev (ev_stat *w) |
991 | |
|
|
992 | MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_ |
|
|
993 | |
|
|
994 | BOOT: |
|
|
995 | { |
|
|
996 | HV *stash = gv_stashpv ("EV::DNS", 1); |
|
|
997 | |
|
|
998 | static const struct { |
|
|
999 | const char *name; |
|
|
1000 | IV iv; |
|
|
1001 | } *civ, const_iv[] = { |
|
|
1002 | # define const_iv(pfx, name) { # name, (IV) pfx ## name }, |
|
|
1003 | const_iv (DNS_, ERR_NONE) |
|
|
1004 | const_iv (DNS_, ERR_FORMAT) |
|
|
1005 | const_iv (DNS_, ERR_SERVERFAILED) |
|
|
1006 | const_iv (DNS_, ERR_NOTEXIST) |
|
|
1007 | const_iv (DNS_, ERR_NOTIMPL) |
|
|
1008 | const_iv (DNS_, ERR_REFUSED) |
|
|
1009 | const_iv (DNS_, ERR_TRUNCATED) |
|
|
1010 | const_iv (DNS_, ERR_UNKNOWN) |
|
|
1011 | const_iv (DNS_, ERR_TIMEOUT) |
|
|
1012 | const_iv (DNS_, ERR_SHUTDOWN) |
|
|
1013 | const_iv (DNS_, IPv4_A) |
|
|
1014 | const_iv (DNS_, PTR) |
|
|
1015 | const_iv (DNS_, IPv6_AAAA) |
|
|
1016 | const_iv (DNS_, QUERY_NO_SEARCH) |
|
|
1017 | const_iv (DNS_, OPTION_SEARCH) |
|
|
1018 | const_iv (DNS_, OPTION_NAMESERVERS) |
|
|
1019 | const_iv (DNS_, OPTION_MISC) |
|
|
1020 | const_iv (DNS_, OPTIONS_ALL) |
|
|
1021 | const_iv (DNS_, NO_SEARCH) |
|
|
1022 | }; |
|
|
1023 | |
|
|
1024 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
|
|
1025 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
|
|
1026 | } |
|
|
1027 | |
|
|
1028 | int evdns_init () |
|
|
1029 | |
|
|
1030 | void evdns_shutdown (int fail_requests = 1) |
|
|
1031 | |
|
|
1032 | const char *evdns_err_to_string (int err) |
|
|
1033 | |
|
|
1034 | int evdns_nameserver_add (U32 address) |
|
|
1035 | |
|
|
1036 | int evdns_count_nameservers () |
|
|
1037 | |
|
|
1038 | int evdns_clear_nameservers_and_suspend () |
|
|
1039 | |
|
|
1040 | int evdns_resume () |
|
|
1041 | |
|
|
1042 | int evdns_nameserver_ip_add (char *ip_as_string) |
|
|
1043 | |
|
|
1044 | int evdns_resolve_ipv4 (const char *name, int flags, SV *cb) |
|
|
1045 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1046 | |
|
|
1047 | int evdns_resolve_ipv6 (const char *name, int flags, SV *cb) |
|
|
1048 | C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb) |
|
|
1049 | |
|
|
1050 | int evdns_resolve_reverse (SV *addr, int flags, SV *cb) |
|
|
1051 | ALIAS: |
930 | ALIAS: |
1052 | evdns_resolve_reverse_ipv6 = 1 |
931 | stat = 1 |
1053 | CODE: |
932 | attr = 2 |
|
|
933 | PPCODE: |
1054 | { |
934 | { |
1055 | STRLEN len; |
935 | ev_statdata *s = ix ? &w->attr : &w->prev; |
1056 | char *data = SvPVbyte (addr, len); |
|
|
1057 | if (len != (ix ? 16 : 4)) |
|
|
1058 | croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string"); |
|
|
1059 | |
936 | |
1060 | RETVAL = ix |
937 | if (ix == 1) |
1061 | ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) |
938 | ev_stat_stat (w); |
1062 | : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); |
939 | else if (!s->st_nlink) |
1063 | } |
940 | errno = ENOENT; |
1064 | OUTPUT: |
|
|
1065 | RETVAL |
|
|
1066 | |
941 | |
1067 | int evdns_set_option (char *option, char *val, int flags) |
942 | PL_statcache.st_dev = s->st_nlink; |
|
|
943 | PL_statcache.st_ino = s->st_ino; |
|
|
944 | PL_statcache.st_mode = s->st_mode; |
|
|
945 | PL_statcache.st_nlink = s->st_nlink; |
|
|
946 | PL_statcache.st_uid = s->st_uid; |
|
|
947 | PL_statcache.st_gid = s->st_gid; |
|
|
948 | PL_statcache.st_rdev = s->st_rdev; |
|
|
949 | PL_statcache.st_size = s->st_size; |
|
|
950 | PL_statcache.st_atime = s->st_atime; |
|
|
951 | PL_statcache.st_mtime = s->st_mtime; |
|
|
952 | PL_statcache.st_ctime = s->st_ctime; |
1068 | |
953 | |
1069 | int evdns_resolv_conf_parse (int flags, const char *filename) |
954 | if (GIMME_V == G_SCALAR) |
1070 | |
955 | XPUSHs (boolSV (s->st_nlink)); |
1071 | #ifdef _WIN32 |
956 | else if (GIMME_V == G_ARRAY && s->st_nlink) |
1072 | |
957 | { |
1073 | int evdns_config_windows_nameservers () |
958 | EXTEND (SP, 13); |
1074 | |
959 | PUSHs (sv_2mortal (newSViv (s->st_dev))); |
1075 | #endif |
960 | PUSHs (sv_2mortal (newSViv (s->st_ino))); |
1076 | |
961 | PUSHs (sv_2mortal (newSVuv (s->st_mode))); |
1077 | void evdns_search_clear () |
962 | PUSHs (sv_2mortal (newSVuv (s->st_nlink))); |
1078 | |
963 | PUSHs (sv_2mortal (newSViv (s->st_uid))); |
1079 | void evdns_search_add (char *domain) |
964 | PUSHs (sv_2mortal (newSViv (s->st_gid))); |
1080 | |
965 | PUSHs (sv_2mortal (newSViv (s->st_rdev))); |
1081 | void evdns_search_ndots_set (int ndots) |
966 | PUSHs (sv_2mortal (newSVnv ((NV)s->st_size))); |
|
|
967 | PUSHs (sv_2mortal (newSVnv (s->st_atime))); |
|
|
968 | PUSHs (sv_2mortal (newSVnv (s->st_mtime))); |
|
|
969 | PUSHs (sv_2mortal (newSVnv (s->st_ctime))); |
|
|
970 | PUSHs (sv_2mortal (newSVuv (4096))); |
|
|
971 | PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); |
|
|
972 | } |
|
|
973 | } |
1082 | |
974 | |
1083 | #if 0 |
975 | #if 0 |
1084 | |
976 | |
1085 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
977 | MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ |
1086 | |
978 | |
… | |
… | |
1120 | |
1012 | |
1121 | #void DESTROY (struct evhttp_request *req); |
1013 | #void DESTROY (struct evhttp_request *req); |
1122 | |
1014 | |
1123 | #endif |
1015 | #endif |
1124 | |
1016 | |
1125 | #endif |
|
|
1126 | |
1017 | |
1127 | |
1018 | |
1128 | |
1019 | |
1129 | |
1020 | |
1130 | |
1021 | |