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.89 by root, Sat Dec 8 14:12:04 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;
409 evapi.invoke = ev_invoke;
472 410
473 sv_setiv (sv, (IV)&evapi); 411 sv_setiv (sv, (IV)&evapi);
474 SvREADONLY_on (sv); 412 SvREADONLY_on (sv);
475 } 413 }
476#ifndef _WIN32 414#ifndef _WIN32
484 422
485NV ev_time () 423NV ev_time ()
486 424
487unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 425unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
488 426
427unsigned int ev_loop_count ()
428
489void ev_loop (int flags = 0) 429void ev_loop (int flags = 0)
490 430
491void ev_unloop (int how = 1) 431void ev_unloop (int how = 1)
432
433void ev_feed_fd_event (int fd, int revents = EV_NONE)
434
435void 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}
492 443
493ev_io *io (SV *fh, int events, SV *cb) 444ev_io *io (SV *fh, int events, SV *cb)
494 ALIAS: 445 ALIAS:
495 io_ns = 1 446 io_ns = 1
496 CODE: 447 CODE:
616 567
617int ev_is_active (ev_watcher *w) 568int ev_is_active (ev_watcher *w)
618 569
619int ev_is_pending (ev_watcher *w) 570int ev_is_pending (ev_watcher *w)
620 571
572void ev_invoke (ev_watcher *w, int revents = EV_NONE)
573
574int ev_clear_pending (ev_watcher *w)
575
576void ev_feed_event (ev_watcher *w, int revents = EV_NONE)
577
621int keepalive (ev_watcher *w, int new_value = 0) 578int keepalive (ev_watcher *w, int new_value = 0)
622 CODE: 579 CODE:
623{ 580{
624 RETVAL = w->flags & WFLAG_KEEPALIVE; 581 RETVAL = w->flags & WFLAG_KEEPALIVE;
625 new_value = new_value ? WFLAG_KEEPALIVE : 0; 582 new_value = new_value ? WFLAG_KEEPALIVE : 0;
657 } 614 }
658} 615}
659 OUTPUT: 616 OUTPUT:
660 RETVAL 617 RETVAL
661 618
662void trigger (ev_watcher *w, int revents = EV_NONE)
663 CODE:
664 w->cb (w, revents);
665
666int priority (ev_watcher *w, int new_priority = 0) 619int priority (ev_watcher *w, int new_priority = 0)
667 CODE: 620 CODE:
668{ 621{
669 RETVAL = w->priority; 622 RETVAL = w->priority;
670 623
671 if (items > 1) 624 if (items > 1)
672 { 625 {
673 int active = ev_is_active (w); 626 int active = ev_is_active (w);
674
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 627
678 if (active) 628 if (active)
679 { 629 {
680 /* grrr. */ 630 /* grrr. */
681 PUSHMARK (SP); 631 PUSHMARK (SP);
682 XPUSHs (ST (0)); 632 XPUSHs (ST (0));
633 PUTBACK;
683 call_method ("stop", G_DISCARD | G_VOID); 634 call_method ("stop", G_DISCARD | G_VOID);
684 } 635 }
685 636
686 ev_set_priority (w, new_priority); 637 ev_set_priority (w, new_priority);
687 638
688 if (active) 639 if (active)
689 { 640 {
690 PUSHMARK (SP); 641 PUSHMARK (SP);
691 XPUSHs (ST (0)); 642 XPUSHs (ST (0));
643 PUTBACK;
692 call_method ("start", G_DISCARD | G_VOID); 644 call_method ("start", G_DISCARD | G_VOID);
693 } 645 }
694 } 646 }
695} 647}
696 OUTPUT: 648 OUTPUT:
1031 PUSHs (sv_2mortal (newSVnv (s->st_ctime))); 983 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1032 PUSHs (sv_2mortal (newSVuv (4096))); 984 PUSHs (sv_2mortal (newSVuv (4096)));
1033 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 985 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1034 } 986 }
1035} 987}
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 988
1130#if 0 989#if 0
1131 990
1132MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 991MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1133 992
1167 1026
1168#void DESTROY (struct evhttp_request *req); 1027#void DESTROY (struct evhttp_request *req);
1169 1028
1170#endif 1029#endif
1171 1030
1172#endif
1173 1031
1174 1032
1175 1033
1176 1034
1177 1035

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines