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.90 by root, Mon Dec 17 07:24:12 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) \
468 evapi.child_start = ev_child_start; 403 evapi.child_start = ev_child_start;
469 evapi.child_stop = ev_child_stop; 404 evapi.child_stop = ev_child_stop;
470 evapi.stat_start = ev_stat_start; 405 evapi.stat_start = ev_stat_start;
471 evapi.stat_stop = ev_stat_stop; 406 evapi.stat_stop = ev_stat_stop;
472 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;
473 410
474 sv_setiv (sv, (IV)&evapi); 411 sv_setiv (sv, (IV)&evapi);
475 SvREADONLY_on (sv); 412 SvREADONLY_on (sv);
476 } 413 }
477#ifndef _WIN32 414#ifndef _WIN32
485 422
486NV ev_time () 423NV ev_time ()
487 424
488unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ()) 425unsigned int ev_default_loop (unsigned int flags = ev_supported_backends ())
489 426
427unsigned int ev_loop_count ()
428
490void ev_loop (int flags = 0) 429void ev_loop (int flags = 0)
491 430
492void 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}
493 443
494ev_io *io (SV *fh, int events, SV *cb) 444ev_io *io (SV *fh, int events, SV *cb)
495 ALIAS: 445 ALIAS:
496 io_ns = 1 446 io_ns = 1
497 CODE: 447 CODE:
617 567
618int ev_is_active (ev_watcher *w) 568int ev_is_active (ev_watcher *w)
619 569
620int ev_is_pending (ev_watcher *w) 570int ev_is_pending (ev_watcher *w)
621 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
622int keepalive (ev_watcher *w, int new_value = 0) 578int keepalive (ev_watcher *w, int new_value = 0)
623 CODE: 579 CODE:
624{ 580{
625 RETVAL = w->flags & WFLAG_KEEPALIVE; 581 RETVAL = w->flags & WFLAG_KEEPALIVE;
626 new_value = new_value ? WFLAG_KEEPALIVE : 0; 582 new_value = new_value ? WFLAG_KEEPALIVE : 0;
658 } 614 }
659} 615}
660 OUTPUT: 616 OUTPUT:
661 RETVAL 617 RETVAL
662 618
663void trigger (ev_watcher *w, int revents = EV_NONE)
664 CODE:
665 w->cb (w, revents);
666
667int priority (ev_watcher *w, int new_priority = 0) 619int priority (ev_watcher *w, int new_priority = 0)
668 CODE: 620 CODE:
669{ 621{
670 RETVAL = w->priority; 622 RETVAL = w->priority;
671 623
672 if (items > 1) 624 if (items > 1)
673 { 625 {
674 int active = ev_is_active (w); 626 int active = ev_is_active (w);
675
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 627
679 if (active) 628 if (active)
680 { 629 {
681 /* grrr. */ 630 /* grrr. */
682 PUSHMARK (SP); 631 PUSHMARK (SP);
683 XPUSHs (ST (0)); 632 XPUSHs (ST (0));
633 PUTBACK;
684 call_method ("stop", G_DISCARD | G_VOID); 634 call_method ("stop", G_DISCARD | G_VOID);
685 } 635 }
686 636
687 ev_set_priority (w, new_priority); 637 ev_set_priority (w, new_priority);
688 638
689 if (active) 639 if (active)
690 { 640 {
691 PUSHMARK (SP); 641 PUSHMARK (SP);
692 XPUSHs (ST (0)); 642 XPUSHs (ST (0));
643 PUTBACK;
693 call_method ("start", G_DISCARD | G_VOID); 644 call_method ("start", G_DISCARD | G_VOID);
694 } 645 }
695 } 646 }
696} 647}
697 OUTPUT: 648 OUTPUT:
821 INIT: 772 INIT:
822 CHECK_REPEAT (repeat); 773 CHECK_REPEAT (repeat);
823 CODE: 774 CODE:
824 RESET (timer, w, (w, after, repeat)); 775 RESET (timer, w, (w, after, repeat));
825 776
777NV at (ev_timer *w)
778 CODE:
779 RETVAL = w->at;
780 OUTPUT:
781 RETVAL
782
826MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 783MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
827 784
828void ev_periodic_start (ev_periodic *w) 785void ev_periodic_start (ev_periodic *w)
829 INIT: 786 INIT:
830 CHECK_REPEAT (w->interval); 787 CHECK_REPEAT (w->interval);
854 SvREFCNT_dec (w->fh); 811 SvREFCNT_dec (w->fh);
855 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; 812 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
856 813
857 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 814 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
858} 815}
816
817NV at (ev_periodic *w)
818 CODE:
819 RETVAL = w->at;
820 OUTPUT:
821 RETVAL
859 822
860MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 823MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
861 824
862void ev_idle_start (ev_idle *w) 825void ev_idle_start (ev_idle *w)
863 CODE: 826 CODE:
1032 PUSHs (sv_2mortal (newSVnv (s->st_ctime))); 995 PUSHs (sv_2mortal (newSVnv (s->st_ctime)));
1033 PUSHs (sv_2mortal (newSVuv (4096))); 996 PUSHs (sv_2mortal (newSVuv (4096)));
1034 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096)))); 997 PUSHs (sv_2mortal (newSVnv ((NV)((s->st_size + 4095) / 4096))));
1035 } 998 }
1036} 999}
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 1000
1131#if 0 1001#if 0
1132 1002
1133MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_ 1003MODULE = EV PACKAGE = EV::HTTP PREFIX = evhttp_
1134 1004
1168 1038
1169#void DESTROY (struct evhttp_request *req); 1039#void DESTROY (struct evhttp_request *req);
1170 1040
1171#endif 1041#endif
1172 1042
1173#endif
1174 1043
1175 1044
1176 1045
1177 1046
1178 1047

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines