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.88 by root, Sat Dec 8 04:02:30 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
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
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 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) \
467 evapi.child_start = ev_child_start; 403 evapi.child_start = ev_child_start;
468 evapi.child_stop = ev_child_stop; 404 evapi.child_stop = ev_child_stop;
469 evapi.stat_start = ev_stat_start; 405 evapi.stat_start = ev_stat_start;
470 evapi.stat_stop = ev_stat_stop; 406 evapi.stat_stop = ev_stat_stop;
471 evapi.stat_stat = ev_stat_stat; 407 evapi.stat_stat = ev_stat_stat;
408 evapi.clear_pending = ev_clear_pending;
472 409
473 sv_setiv (sv, (IV)&evapi); 410 sv_setiv (sv, (IV)&evapi);
474 SvREADONLY_on (sv); 411 SvREADONLY_on (sv);
475 } 412 }
476#ifndef _WIN32 413#ifndef _WIN32
484 421
485NV ev_time () 422NV ev_time ()
486 423
487unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 424unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
488 425
426unsigned int ev_loop_count ()
427
489void ev_loop (int flags = 0) 428void ev_loop (int flags = 0)
490 429
491void ev_unloop (int how = 1) 430void ev_unloop (int how = 1)
492 431
493ev_io *io (SV *fh, int events, SV *cb) 432ev_io *io (SV *fh, int events, SV *cb)
670 609
671 if (items > 1) 610 if (items > 1)
672 { 611 {
673 int active = ev_is_active (w); 612 int active = ev_is_active (w);
674 613
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
678 if (active) 614 if (active)
679 { 615 {
680 /* grrr. */ 616 /* grrr. */
681 PUSHMARK (SP); 617 PUSHMARK (SP);
682 XPUSHs (ST (0)); 618 XPUSHs (ST (0));
619 PUTBACK;
683 call_method ("stop", G_DISCARD | G_VOID); 620 call_method ("stop", G_DISCARD | G_VOID);
684 } 621 }
685 622
686 ev_set_priority (w, new_priority); 623 ev_set_priority (w, new_priority);
687 624
688 if (active) 625 if (active)
689 { 626 {
690 PUSHMARK (SP); 627 PUSHMARK (SP);
691 XPUSHs (ST (0)); 628 XPUSHs (ST (0));
629 PUTBACK;
692 call_method ("start", G_DISCARD | G_VOID); 630 call_method ("start", G_DISCARD | G_VOID);
693 } 631 }
694 } 632 }
695} 633}
696 OUTPUT: 634 OUTPUT:
1031 PUSHs (sv_2mortal (newSVnv (s->st_ctime))); 969 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1032 PUSHs (sv_2mortal (newSVuv (4096))); 970 PUSHs (sv_2mortal (newSVuv (4096)));
1033 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 971 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1034 } 972 }
1035} 973}
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 974
1130#if 0 975#if 0
1131 976
1132MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 977MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1133 978
1167 1012
1168#void DESTROY (struct evhttp_request *req); 1013#void DESTROY (struct evhttp_request *req);
1169 1014
1170#endif 1015#endif
1171 1016
1172#endif
1173 1017
1174 1018
1175 1019
1176 1020
1177 1021

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines