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

Comparing EV/EV.xs (file contents):
Revision 1.81 by root, Tue Nov 27 10:59:10 2007 UTC vs.
Revision 1.85 by root, Sat Dec 1 22:51:34 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
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
306 FREETMPS; 295 FREETMPS;
307 LEAVE; 296 LEAVE;
308 297
309 return retval; 298 return retval;
310} 299}
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 300
366#define CHECK_REPEAT(repeat) if (repeat < 0.) \ 301#define CHECK_REPEAT(repeat) if (repeat < 0.) \
367 croak (# repeat " value must be >= 0"); 302 croak (# repeat " value must be >= 0");
368 303
369#define CHECK_FD(fh,fd) if ((fd) < 0) \ 304#define CHECK_FD(fh,fd) if ((fd) < 0) \
412 const_iv (EV, BACKEND_KQUEUE) 347 const_iv (EV, BACKEND_KQUEUE)
413 const_iv (EV, BACKEND_DEVPOLL) 348 const_iv (EV, BACKEND_DEVPOLL)
414 const_iv (EV, BACKEND_PORT) 349 const_iv (EV, BACKEND_PORT)
415 const_iv (EV, FLAG_AUTO) 350 const_iv (EV, FLAG_AUTO)
416 const_iv (EV, FLAG_NOENV) 351 const_iv (EV, FLAG_NOENV)
352 const_iv (EV, FLAG_FORKCHECK)
417 }; 353 };
418 354
419 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 355 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
420 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 356 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
421 357
985 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval)); 921 RESET (stat, w, (w, SvPVbyte_nolen (w->fh), new_interval));
986} 922}
987 OUTPUT: 923 OUTPUT:
988 RETVAL 924 RETVAL
989 925
990#ifndef _WIN32 926void prev (ev_stat *w)
991
992MODULE = EV PACKAGE = EV::DNS PREFIX = evdns_
993
994BOOT:
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
1028int evdns_init ()
1029
1030void evdns_shutdown (int fail_requests = 1)
1031
1032const char *evdns_err_to_string (int err)
1033
1034int evdns_nameserver_add (U32 address)
1035
1036int evdns_count_nameservers ()
1037
1038int evdns_clear_nameservers_and_suspend ()
1039
1040int evdns_resume ()
1041
1042int evdns_nameserver_ip_add (char *ip_as_string)
1043
1044int evdns_resolve_ipv4 (const char *name, int flags, SV *cb)
1045 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1046
1047int evdns_resolve_ipv6 (const char *name, int flags, SV *cb)
1048 C_ARGS: name, flags, dns_cb, (void *)SvREFCNT_inc (cb)
1049
1050int evdns_resolve_reverse (SV *addr, int flags, SV *cb)
1051 ALIAS: 927 ALIAS:
1052 evdns_resolve_reverse_ipv6 = 1 928 stat = 1
1053 CODE: 929 attr = 2
930 PPCODE:
1054{ 931{
1055 STRLEN len; 932 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 933
1060 RETVAL = ix 934 if (ix == 1)
1061 ? evdns_resolve_reverse_ipv6 ((struct in6_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)) 935 ev_stat_stat (w);
1062 : evdns_resolve_reverse ((struct in_addr *)data, flags, dns_cb, (void *)SvREFCNT_inc (cb)); 936 else if (!s->st_nlink)
1063} 937 errno = ENOENT;
1064 OUTPUT:
1065 RETVAL
1066 938
1067int evdns_set_option (char *option, char *val, int flags) 939 PL_statcache.st_dev = s->st_nlink;
940 PL_statcache.st_ino = s->st_ino;
941 PL_statcache.st_mode = s->st_mode;
942 PL_statcache.st_nlink = s->st_nlink;
943 PL_statcache.st_uid = s->st_uid;
944 PL_statcache.st_gid = s->st_gid;
945 PL_statcache.st_rdev = s->st_rdev;
946 PL_statcache.st_size = s->st_size;
947 PL_statcache.st_atime = s->st_atime;
948 PL_statcache.st_mtime = s->st_mtime;
949 PL_statcache.st_ctime = s->st_ctime;
1068 950
1069int evdns_resolv_conf_parse (int flags, const char *filename) 951 if (GIMME_V == G_SCALAR)
1070 952 XPUSHs (boolSV (s->st_nlink));
1071#ifdef _WIN32 953 else if (GIMME_V == G_ARRAY && s->st_nlink)
1072 954 {
1073int evdns_config_windows_nameservers () 955 EXTEND (SP, 13);
1074 956 PUSHs (sv_2mortal (newSViv (s->st_dev)));
1075#endif 957 PUSHs (sv_2mortal (newSViv (s->st_ino)));
1076 958 PUSHs (sv_2mortal (newSVuv (s->st_mode)));
1077void evdns_search_clear () 959 PUSHs (sv_2mortal (newSVuv (s->st_nlink)));
1078 960 PUSHs (sv_2mortal (newSViv (s->st_uid)));
1079void evdns_search_add (char *domain) 961 PUSHs (sv_2mortal (newSViv (s->st_gid)));
1080 962 PUSHs (sv_2mortal (newSViv (s->st_rdev)));
1081void evdns_search_ndots_set (int ndots) 963 PUSHs (sv_2mortal (newSVnv ((NV)s->st_size)));
964 PUSHs (sv_2mortal (newSVnv (s->st_atime)));
965 PUSHs (sv_2mortal (newSVnv (s->st_mtime)));
966 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
967 PUSHs (sv_2mortal (newSVuv (4096)));
968 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
969 }
970}
1082 971
1083#if 0 972#if 0
1084 973
1085MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 974MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1086 975
1120 1009
1121#void DESTROY (struct evhttp_request *req); 1010#void DESTROY (struct evhttp_request *req);
1122 1011
1123#endif 1012#endif
1124 1013
1125#endif
1126 1014
1127 1015
1128 1016
1129 1017
1130 1018

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines