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

Comparing EV/EV.xs (file contents):
Revision 1.84 by root, Sat Dec 1 15:32:53 2007 UTC vs.
Revision 1.87 by root, Fri Dec 7 18:09:38 2007 UTC

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
256 else 244 else
257 sv_events_cache = sv_events; 245 sv_events_cache = sv_events;
258 246
259 if (SvTRUE (ERRSV)) 247 if (SvTRUE (ERRSV))
260 { 248 {
249 SPAGAIN;
261 PUSHMARK (SP); 250 PUSHMARK (SP);
262 PUTBACK; 251 PUTBACK;
263 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);
264 } 253 }
265 254
307 FREETMPS; 296 FREETMPS;
308 LEAVE; 297 LEAVE;
309 298
310 return retval; 299 return retval;
311} 300}
312
313/////////////////////////////////////////////////////////////////////////////
314// DNS
315
316#ifndef _WIN32
317static void
318dns_cb (int result, char type, int count, int ttl, void *addresses, void *arg)
319{
320 dSP;
321 SV *cb = (SV *)arg;
322
323 ENTER;
324 SAVETMPS;
325 PUSHMARK (SP);
326 EXTEND (SP, count + 3);
327 PUSHs (sv_2mortal (newSViv (result)));
328
329 if (result == DNS_ERR_NONE && ttl >= 0)
330 {
331 int i;
332
333 PUSHs (sv_2mortal (newSViv (type)));
334 PUSHs (sv_2mortal (newSViv (ttl)));
335
336 for (i = 0; i < count; ++i)
337 switch (type)
338 {
339 case DNS_IPv6_AAAA:
340 PUSHs (sv_2mortal (newSVpvn (i * 16 + (char *)addresses, 16)));
341 break;
342 case DNS_IPv4_A:
343 PUSHs (sv_2mortal (newSVpvn (i * 4 + (char *)addresses, 4)));
344 break;
345 case DNS_PTR:
346 PUSHs (sv_2mortal (newSVpv (*(char **)addresses, 0)));
347 break;
348 }
349 }
350
351 PUTBACK;
352 call_sv (sv_2mortal (cb), G_DISCARD | G_VOID | G_EVAL);
353
354 FREETMPS;
355
356 if (SvTRUE (ERRSV))
357 {
358 PUSHMARK (SP);
359 PUTBACK;
360 call_sv (get_sv ("EV::DIED", 1), G_DISCARD | G_VOID | G_EVAL | G_KEEPERR);
361 }
362
363 LEAVE;
364}
365#endif
366 301
367#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 302#define CHECK_REPEAT(repeat) if (repeat < 0.) \
368 croak (# repeat " value must be >= 0"); 303 croak (# repeat " value must be >= 0");
369 304
370#define CHECK_FD(fh,fd) if ((fd) < 0) \ 305#define CHECK_FD(fh,fd) if ((fd) < 0) \
485 420
486NV ev_time () 421NV ev_time ()
487 422
488unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 423unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
489 424
425unsigned int ev_loop_count ()
426
490void ev_loop (int flags = 0) 427void ev_loop (int flags = 0)
491 428
492void ev_unloop (int how = 1) 429void ev_unloop (int how = 1)
493 430
494ev_io *io (SV *fh, int events, SV *cb) 431ev_io *io (SV *fh, int events, SV *cb)
671 608
672 if (items > 1) 609 if (items > 1)
673 { 610 {
674 int active = ev_is_active (w); 611 int active = ev_is_active (w);
675 612
676 if (new_priority < EV_MINPRI || new_priority > EV_MAXPRI)
677 croak ("watcher priority out of range, value must be between %d and %d, inclusive", EV_MINPRI, EV_MAXPRI);
678
679 if (active) 613 if (active)
680 { 614 {
681 /* grrr. */ 615 /* grrr. */
682 PUSHMARK (SP); 616 PUSHMARK (SP);
683 XPUSHs (ST (0)); 617 XPUSHs (ST (0));
618 PUTBACK;
684 call_method ("stop", G_DISCARD | G_VOID); 619 call_method ("stop", G_DISCARD | G_VOID);
685 } 620 }
686 621
687 ev_set_priority (w, new_priority); 622 ev_set_priority (w, new_priority);
688 623
689 if (active) 624 if (active)
690 { 625 {
691 PUSHMARK (SP); 626 PUSHMARK (SP);
692 XPUSHs (ST (0)); 627 XPUSHs (ST (0));
628 PUTBACK;
693 call_method ("start", G_DISCARD | G_VOID); 629 call_method ("start", G_DISCARD | G_VOID);
694 } 630 }
695 } 631 }
696} 632}
697 OUTPUT: 633 OUTPUT:
1032 PUSHs (sv_2mortal (newSVnv (s->st_ctime))); 968 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1033 PUSHs (sv_2mortal (newSVuv (4096))); 969 PUSHs (sv_2mortal (newSVuv (4096)));
1034 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 970 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1035 } 971 }
1036} 972}
1037
1038#ifndef _WIN32
1039
1040MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
1041
1042BOOT:
1043{
1044 HV *stash = gv_stashpv ("EV::DNS", 1);
1045
1046 static const struct {
1047 const char *name;
1048 IV iv;
1049 } *civ, const_iv[] = {
1050# define const_iv(pfx, name) { # name, (IV) pfx ## name },
1051 const_iv (DNS_, ERR_NONE)
1052 const_iv (DNS_, ERR_FORMAT)
1053 const_iv (DNS_, ERR_SERVERFAILED)
1054 const_iv (DNS_, ERR_NOTEXIST)
1055 const_iv (DNS_, ERR_NOTIMPL)
1056 const_iv (DNS_, ERR_REFUSED)
1057 const_iv (DNS_, ERR_TRUNCATED)
1058 const_iv (DNS_, ERR_UNKNOWN)
1059 const_iv (DNS_, ERR_TIMEOUT)
1060 const_iv (DNS_, ERR_SHUTDOWN)
1061 const_iv (DNS_, IPv4_A)
1062 const_iv (DNS_, PTR)
1063 const_iv (DNS_, IPv6_AAAA)
1064 const_iv (DNS_, QUERY_NO_SEARCH)
1065 const_iv (DNS_, OPTION_SEARCH)
1066 const_iv (DNS_, OPTION_NAMESERVERS)
1067 const_iv (DNS_, OPTION_MISC)
1068 const_iv (DNS_, OPTIONS_ALL)
1069 const_iv (DNS_, NO_SEARCH)
1070 };
1071
1072 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1073 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1074}
1075
1076int evdns_init ()
1077
1078void evdns_shutdown (int fail_requests = 1)
1079
1080const char *evdns_err_to_string (int err)
1081
1082int evdns_nameserver_add (U32 address)
1083
1084int evdns_count_nameservers ()
1085
1086int evdns_clear_nameservers_and_suspend ()
1087
1088int evdns_resume ()
1089
1090int evdns_nameserver_ip_add (char *ip_as_string)
1091
1092int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
1093 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1094
1095int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
1096 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1097
1098int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
1099 ALIAS:
1100 evdns_resolve_reverse_ipv6 = 1
1101 CODE:
1102{
1103 STRLEN len;
1104 char *data = SvPVbyte (addr, len);
1105 if (len != (ix ? 16 : 4))
1106 croak ("ipv4/ipv6 address to be resolved must be given as 4/16 byte octet string");
1107
1108 RETVAL = ix
1109 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb))
1110 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb));
1111}
1112 OUTPUT:
1113 RETVAL
1114
1115int evdns_set_option (char *option, char *val, int flags)
1116
1117int evdns_resolv_conf_parse (int flags, const char *filename)
1118
1119#ifdef _WIN32
1120
1121int evdns_config_windows_nameservers ()
1122
1123#endif
1124
1125void evdns_search_clear ()
1126
1127void evdns_search_add (char *domain)
1128
1129void evdns_search_ndots_set (int ndots)
1130 973
1131#if 0 974#if 0
1132 975
1133MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 976MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1134 977
1168 1011
1169#void DESTROY (struct evhttp_request *req); 1012#void DESTROY (struct evhttp_request *req);
1170 1013
1171#endif 1014#endif
1172 1015
1173#endif
1174 1016
1175 1017
1176 1018
1177 1019
1178 1020

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines