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

Comparing EV/EV.xs (file contents):
Revision 1.96 by root, Thu Dec 20 10:12:22 2007 UTC vs.
Revision 1.115 by root, Mon Sep 8 17:27:42 2008 UTC

2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5/*#include <netinet/in.h>*/ 5/*#include <netinet/in.h>*/
6 6
7#define EV_PROTOTYPES 1
8#define EV_H <ev.h>
9#include "EV/EVAPI.h"
10
11/* fix perl api breakage */ 7/* fix perl api breakage */
12#undef signal 8#undef signal
13#undef sigaction 9#undef sigaction
10
11#define EV_PROTOTYPES 1
12#define EV_USE_NANOSLEEP EV_USE_MONOTONIC
13#define EV_H <ev.h>
14#include "EV/EVAPI.h"
14 15
15#define EV_SELECT_IS_WINSOCKET 0 16#define EV_SELECT_IS_WINSOCKET 0
16#ifdef _WIN32 17#ifdef _WIN32
17# define EV_SELECT_USE_FD_SET 0 18# define EV_SELECT_USE_FD_SET 0
18# define NFDBITS PERL_NFDBITS 19# define NFDBITS PERL_NFDBITS
28#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop)) 29#define e_loop(w) INT2PTR (struct ev_loop *, SvIVX ((w)->loop))
29 30
30#define WFLAG_KEEPALIVE 1 31#define WFLAG_KEEPALIVE 1
31 32
32#define UNREF(w) \ 33#define UNREF(w) \
33 if (!((w)->flags & WFLAG_KEEPALIVE) \ 34 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
34 && !ev_is_active (w)) \ 35 && !ev_is_active (w)) \
35 ev_unref (e_loop (w)); 36 ev_unref (e_loop (w));
36 37
37#define REF(w) \ 38#define REF(w) \
38 if (!((w)->flags & WFLAG_KEEPALIVE) \ 39 if (!((w)->e_flags & WFLAG_KEEPALIVE) \
39 && ev_is_active (w)) \ 40 && ev_is_active (w)) \
40 ev_ref (e_loop (w)); 41 ev_ref (e_loop (w));
41 42
42#define START(type,w) \ 43#define START(type,w) \
43 do { \ 44 do { \
44 UNREF (w); \ 45 UNREF (w); \
45 ev_ ## type ## _start (e_loop (w), w); \ 46 ev_ ## type ## _start (e_loop (w), w); \
46 } while (0) 47 } while (0)
47 48
48#define STOP(type,w) \ 49#define STOP(type,w) \
49 do { \ 50 do { \
50 REF (w); \ 51 REF (w); \
51 ev_ ## type ## _stop (e_loop (w), w); \ 52 ev_ ## type ## _stop (e_loop (w), w); \
52 } while (0) 53 } while (0)
53 54
54#define RESET(type,w,seta) \ 55#define RESET(type,w,seta) \
55 do { \ 56 do { \
56 int active = ev_is_active (w); \ 57 int active = ev_is_active (w); \
76 *stash_stat, 77 *stash_stat,
77 *stash_idle, 78 *stash_idle,
78 *stash_prepare, 79 *stash_prepare,
79 *stash_check, 80 *stash_check,
80 *stash_embed, 81 *stash_embed,
81 *stash_fork; 82 *stash_fork,
83 *stash_async;
82 84
83#ifndef SIG_SIZE 85#ifndef SIG_SIZE
84/* kudos to Slaven Rezic for the idea */ 86/* kudos to Slaven Rezic for the idea */
85static char sig_size [] = { SIG_NUM }; 87static char sig_size [] = { SIG_NUM };
86# define SIG_SIZE (sizeof (sig_size) + 1) 88# define SIG_SIZE (sizeof (sig_size) + 1)
125 return SvIV (fh); 127 return SvIV (fh);
126 128
127 return -1; 129 return -1;
128} 130}
129 131
132static SV *
133e_get_cv (SV *cb_sv)
134{
135 HV *st;
136 GV *gvp;
137 CV *cv = sv_2cv (cb_sv, &st, &gvp, 0);
138
139 if (!cv)
140 croak ("EV watcher callback must be a CODE reference");
141
142 return (SV *)cv;
143}
144
130static void * 145static void *
131e_new (int size, SV *cb_sv, SV *loop) 146e_new (int size, SV *cb_sv, SV *loop)
132{ 147{
148 SV *cv = cb_sv ? e_get_cv (cb_sv) : 0;
133 ev_watcher *w; 149 ev_watcher *w;
134 SV *self = NEWSV (0, size); 150 SV *self = NEWSV (0, size);
135 SvPOK_only (self); 151 SvPOK_only (self);
136 SvCUR_set (self, size); 152 SvCUR_set (self, size);
137 153
138 w = (ev_watcher *)SvPVX (self); 154 w = (ev_watcher *)SvPVX (self);
139 155
140 ev_init (w, e_cb); 156 ev_init (w, cv ? e_cb : 0);
141 157
142 w->loop = SvREFCNT_inc (SvRV (loop)); 158 w->loop = SvREFCNT_inc (SvRV (loop));
143 w->flags = WFLAG_KEEPALIVE; 159 w->e_flags = WFLAG_KEEPALIVE;
144 w->data = 0; 160 w->data = 0;
145 w->fh = 0; 161 w->fh = 0;
146 w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); 162 w->cb_sv = SvREFCNT_inc (cv);
147 w->self = self; 163 w->self = self;
148 164
149 return (void *)w; 165 return (void *)w;
150} 166}
151 167
152static void 168static void
374 stash_check = gv_stashpv ("EV::Check" , 1); 390 stash_check = gv_stashpv ("EV::Check" , 1);
375 stash_child = gv_stashpv ("EV::Child" , 1); 391 stash_child = gv_stashpv ("EV::Child" , 1);
376 stash_embed = gv_stashpv ("EV::Embed" , 1); 392 stash_embed = gv_stashpv ("EV::Embed" , 1);
377 stash_stat = gv_stashpv ("EV::Stat" , 1); 393 stash_stat = gv_stashpv ("EV::Stat" , 1);
378 stash_fork = gv_stashpv ("EV::Fork" , 1); 394 stash_fork = gv_stashpv ("EV::Fork" , 1);
395 stash_async = gv_stashpv ("EV::Async" , 1);
379 396
380 { 397 {
381 SV *sv = perl_get_sv ("EV::API", TRUE); 398 SV *sv = perl_get_sv ("EV::API", TRUE);
382 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */ 399 perl_get_sv ("EV::API", TRUE); /* silence 5.10 warning */
383 400
387 evapi.sv_fileno = sv_fileno; 404 evapi.sv_fileno = sv_fileno;
388 evapi.sv_signum = sv_signum; 405 evapi.sv_signum = sv_signum;
389 evapi.supported_backends = ev_supported_backends (); 406 evapi.supported_backends = ev_supported_backends ();
390 evapi.recommended_backends = ev_recommended_backends (); 407 evapi.recommended_backends = ev_recommended_backends ();
391 evapi.embeddable_backends = ev_embeddable_backends (); 408 evapi.embeddable_backends = ev_embeddable_backends ();
392 evapi.time = ev_time; 409 evapi.time_ = ev_time;
410 evapi.sleep_ = ev_sleep;
393 evapi.loop_new = ev_loop_new; 411 evapi.loop_new = ev_loop_new;
394 evapi.loop_destroy = ev_loop_destroy; 412 evapi.loop_destroy = ev_loop_destroy;
395 evapi.loop_fork = ev_loop_fork; 413 evapi.loop_fork = ev_loop_fork;
396 evapi.loop_count = ev_loop_count; 414 evapi.loop_count = ev_loop_count;
397 evapi.now = ev_now; 415 evapi.now = ev_now;
416 evapi.now_update = ev_now_update;
398 evapi.backend = ev_backend; 417 evapi.backend = ev_backend;
399 evapi.unloop = ev_unloop; 418 evapi.unloop = ev_unloop;
400 evapi.ref = ev_ref; 419 evapi.ref = ev_ref;
401 evapi.unref = ev_unref; 420 evapi.unref = ev_unref;
402 evapi.loop = ev_loop; 421 evapi.loop = ev_loop;
424 evapi.embed_start = ev_embed_start; 443 evapi.embed_start = ev_embed_start;
425 evapi.embed_stop = ev_embed_stop; 444 evapi.embed_stop = ev_embed_stop;
426 evapi.embed_sweep = ev_embed_sweep; 445 evapi.embed_sweep = ev_embed_sweep;
427 evapi.fork_start = ev_fork_start; 446 evapi.fork_start = ev_fork_start;
428 evapi.fork_stop = ev_fork_stop; 447 evapi.fork_stop = ev_fork_stop;
448 evapi.async_start = ev_async_start;
449 evapi.async_stop = ev_async_stop;
450 evapi.async_send = ev_async_send;
429 evapi.clear_pending = ev_clear_pending; 451 evapi.clear_pending = ev_clear_pending;
430 evapi.invoke = ev_invoke; 452 evapi.invoke = ev_invoke;
431 453
432 sv_setiv (sv, (IV)&evapi); 454 sv_setiv (sv, (IV)&evapi);
433 SvREADONLY_on (sv); 455 SvREADONLY_on (sv);
435#ifndef _WIN32 457#ifndef _WIN32
436 pthread_atfork (0, 0, ev_default_fork); 458 pthread_atfork (0, 0, ev_default_fork);
437#endif 459#endif
438} 460}
439 461
440SV *ev_default_loop (unsigned int flags = ev_supported_backends ()) 462SV *ev_default_loop (unsigned int flags = 0)
441 CODE: 463 CODE:
442{ 464{
443 if (!default_loop_sv) 465 if (!default_loop_sv)
444 { 466 {
445 evapi.default_loop = ev_default_loop (flags); 467 evapi.default_loop = ev_default_loop (flags);
453 RETVAL = newSVsv (default_loop_sv); 475 RETVAL = newSVsv (default_loop_sv);
454} 476}
455 OUTPUT: 477 OUTPUT:
456 RETVAL 478 RETVAL
457 479
480void ev_default_destroy ()
481 CODE:
482 ev_default_destroy ();
483 SvREFCNT_dec (default_loop_sv);
484 default_loop_sv = 0;
485
486unsigned int ev_supported_backends ()
487
488unsigned int ev_recommended_backends ()
489
490unsigned int ev_embeddable_backends ()
491
458NV ev_time () 492NV ev_time ()
459 493
460NV ev_now () 494NV ev_now ()
461 C_ARGS: evapi.default_loop 495 C_ARGS: evapi.default_loop
462 496
497void ev_now_update ()
498 C_ARGS: evapi.default_loop
499
463unsigned int ev_backend () 500unsigned int ev_backend ()
464 C_ARGS: evapi.default_loop 501 C_ARGS: evapi.default_loop
465 502
466unsigned int ev_loop_count () 503unsigned int ev_loop_count ()
467 C_ARGS: evapi.default_loop 504 C_ARGS: evapi.default_loop
468 505
506void ev_set_io_collect_interval (NV interval)
507 C_ARGS: evapi.default_loop, interval
508
509void ev_set_timeout_collect_interval (NV interval)
510 C_ARGS: evapi.default_loop, interval
511
469void ev_loop (int flags = 0) 512void ev_loop (int flags = 0)
470 C_ARGS: evapi.default_loop, flags 513 C_ARGS: evapi.default_loop, flags
471 514
472void ev_unloop (int how = 1) 515void ev_unloop (int how = EVUNLOOP_ONE)
473 C_ARGS: evapi.default_loop, how 516 C_ARGS: evapi.default_loop, how
474 517
475void ev_feed_fd_event (int fd, int revents = EV_NONE) 518void ev_feed_fd_event (int fd, int revents = EV_NONE)
476 C_ARGS: evapi.default_loop, fd, revents 519 C_ARGS: evapi.default_loop, fd, revents
477 520
582 ev_fork_set (RETVAL); 625 ev_fork_set (RETVAL);
583 if (!ix) START (fork, RETVAL); 626 if (!ix) START (fork, RETVAL);
584 OUTPUT: 627 OUTPUT:
585 RETVAL 628 RETVAL
586 629
587ev_child *child (int pid, SV *cb) 630ev_child *child (int pid, int trace, SV *cb)
588 ALIAS: 631 ALIAS:
589 child_ns = 1 632 child_ns = 1
590 CODE: 633 CODE:
591 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); 634 RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv);
592 ev_child_set (RETVAL, pid); 635 ev_child_set (RETVAL, pid, trace);
593 if (!ix) START (child, RETVAL); 636 if (!ix) START (child, RETVAL);
594 OUTPUT: 637 OUTPUT:
595 RETVAL 638 RETVAL
596 639
597ev_stat *stat (SV *path, NV interval, SV *cb) 640ev_stat *stat (SV *path, NV interval, SV *cb)
603 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); 646 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
604 if (!ix) START (stat, RETVAL); 647 if (!ix) START (stat, RETVAL);
605 OUTPUT: 648 OUTPUT:
606 RETVAL 649 RETVAL
607 650
608ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef) 651ev_embed *embed (struct ev_loop *loop, SV *cb = 0)
609 ALIAS: 652 ALIAS:
610 embed_ns = 1 653 embed_ns = 1
611 CODE: 654 CODE:
612{ 655{
613 if (!(ev_backend (loop) & ev_embeddable_backends ())) 656 if (!(ev_backend (loop) & ev_embeddable_backends ()))
614 croak ("passed loop is not embeddable via EV::embed,"); 657 croak ("passed loop is not embeddable via EV::embed,");
615 658
616 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); 659 RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv);
617 RETVAL->fh = newSVsv (ST (0)); 660 RETVAL->fh = newSVsv (ST (0));
618 ev_embed_set (RETVAL, loop); 661 ev_embed_set (RETVAL, loop);
619
620 if (!SvOK (cb)) ev_set_cb (RETVAL, 0);
621
622 if (!ix) START (embed, RETVAL); 662 if (!ix) START (embed, RETVAL);
623} 663}
664 OUTPUT:
665 RETVAL
666
667ev_async *async (SV *cb)
668 ALIAS:
669 async_ns = 1
670 CODE:
671 RETVAL = e_new (sizeof (ev_async), cb, default_loop_sv);
672 ev_async_set (RETVAL);
673 if (!ix) START (async, RETVAL);
624 OUTPUT: 674 OUTPUT:
625 RETVAL 675 RETVAL
626 676
627void once (SV *fh, int events, SV *timeout, SV *cb) 677void once (SV *fh, int events, SV *timeout, SV *cb)
628 CODE: 678 CODE:
652 C_ARGS: e_loop (w), w, revents 702 C_ARGS: e_loop (w), w, revents
653 703
654int keepalive (ev_watcher *w, int new_value = 0) 704int keepalive (ev_watcher *w, int new_value = 0)
655 CODE: 705 CODE:
656{ 706{
657 RETVAL = w->flags & WFLAG_KEEPALIVE; 707 RETVAL = w->e_flags & WFLAG_KEEPALIVE;
658 new_value = new_value ? WFLAG_KEEPALIVE : 0; 708 new_value = new_value ? WFLAG_KEEPALIVE : 0;
659 709
660 if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) 710 if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE))
661 { 711 {
662 REF (w); 712 REF (w);
663 w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; 713 w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value;
664 UNREF (w); 714 UNREF (w);
665 } 715 }
666} 716}
667 OUTPUT: 717 OUTPUT:
668 RETVAL 718 RETVAL
669 719
670SV *cb (ev_watcher *w, SV *new_cb = 0) 720SV *cb (ev_watcher *w, SV *new_cb = 0)
671 CODE: 721 CODE:
672{ 722{
673 RETVAL = newSVsv (w->cb_sv);
674
675 if (items > 1) 723 if (items > 1)
676 sv_setsv (w->cb_sv, new_cb); 724 {
725 new_cb = e_get_cv (new_cb);
726 RETVAL = newRV_noinc (w->cb_sv);
727 w->cb_sv = SvREFCNT_inc (new_cb);
728 }
729 else
730 RETVAL = newRV_inc (w->cb_sv);
677} 731}
678 OUTPUT: 732 OUTPUT:
679 RETVAL 733 RETVAL
680 734
681SV *data (ev_watcher *w, SV *new_data = 0) 735SV *data (ev_watcher *w, SV *new_data = 0)
687 { 741 {
688 SvREFCNT_dec (w->data); 742 SvREFCNT_dec (w->data);
689 w->data = newSVsv (new_data); 743 w->data = newSVsv (new_data);
690 } 744 }
691} 745}
746 OUTPUT:
747 RETVAL
748
749SV *loop (ev_watcher *w)
750 CODE:
751 RETVAL = newRV_inc (w->loop);
692 OUTPUT: 752 OUTPUT:
693 RETVAL 753 RETVAL
694 754
695int priority (ev_watcher *w, int new_priority = 0) 755int priority (ev_watcher *w, int new_priority = 0)
696 CODE: 756 CODE:
848 INIT: 908 INIT:
849 CHECK_REPEAT (repeat); 909 CHECK_REPEAT (repeat);
850 CODE: 910 CODE:
851 RESET (timer, w, (w, after, repeat)); 911 RESET (timer, w, (w, after, repeat));
852 912
853NV at (ev_timer *w)
854 CODE:
855 RETVAL = w->at;
856 OUTPUT:
857 RETVAL
858
859MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ 913MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_
860 914
861void ev_periodic_start (ev_periodic *w) 915void ev_periodic_start (ev_periodic *w)
862 INIT: 916 INIT:
863 CHECK_REPEAT (w->interval); 917 CHECK_REPEAT (w->interval);
890 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0)); 944 RESET (periodic, w, (w, at, interval, w->fh ? e_periodic_cb : 0));
891} 945}
892 946
893NV at (ev_periodic *w) 947NV at (ev_periodic *w)
894 CODE: 948 CODE:
895 RETVAL = w->at; 949 RETVAL = ev_periodic_at (w);
896 OUTPUT: 950 OUTPUT:
897 RETVAL 951 RETVAL
898 952
899MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ 953MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_
900 954
909void DESTROY (ev_idle *w) 963void DESTROY (ev_idle *w)
910 CODE: 964 CODE:
911 STOP (idle, w); 965 STOP (idle, w);
912 e_destroy (w); 966 e_destroy (w);
913 967
914MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ 968MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_
915 969
916void ev_prepare_start (ev_prepare *w) 970void ev_prepare_start (ev_prepare *w)
917 CODE: 971 CODE:
918 START (prepare, w); 972 START (prepare, w);
919 973
969void DESTROY (ev_child *w) 1023void DESTROY (ev_child *w)
970 CODE: 1024 CODE:
971 STOP (child, w); 1025 STOP (child, w);
972 e_destroy (w); 1026 e_destroy (w);
973 1027
974void set (ev_child *w, int pid) 1028void set (ev_child *w, int pid, int trace)
975 CODE: 1029 CODE:
976 RESET (child, w, (w, pid)); 1030 RESET (child, w, (w, pid, trace));
977 1031
978int pid (ev_child *w, int new_pid = 0)
979 CODE:
980{
981 RETVAL = w->pid;
982
983 if (items > 1)
984 RESET (child, w, (w, new_pid));
985}
986 OUTPUT:
987 RETVAL
988
989
990int rstatus (ev_child *w) 1032int pid (ev_child *w)
991 ALIAS: 1033 ALIAS:
992 rpid = 1 1034 rpid = 1
1035 rstatus = 2
993 CODE: 1036 CODE:
994 RETVAL = ix ? w->rpid : w->rstatus; 1037 RETVAL = ix == 0 ? w->pid
1038 : ix == 1 ? w->rpid
1039 : w->rstatus;
995 OUTPUT: 1040 OUTPUT:
996 RETVAL 1041 RETVAL
997 1042
998MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ 1043MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_
999 1044
1115 CODE: 1160 CODE:
1116 RETVAL = newSVsv (w->fh); 1161 RETVAL = newSVsv (w->fh);
1117 OUTPUT: 1162 OUTPUT:
1118 RETVAL 1163 RETVAL
1119 1164
1165void ev_embed_sweep (ev_embed *w)
1166 C_ARGS: e_loop (w), w
1167
1168MODULE = EV PACKAGE = EV::Async PREFIX = ev_async_
1169
1170void ev_async_start (ev_async *w)
1171 CODE:
1172 START (async, w);
1173
1174void ev_async_stop (ev_async *w)
1175 CODE:
1176 STOP (async, w);
1177
1178void DESTROY (ev_async *w)
1179 CODE:
1180 STOP (async, w);
1181 e_destroy (w);
1182
1183void ev_async_send (ev_async *w)
1184 C_ARGS: e_loop (w), w
1185
1186SV *ev_async_async_pending (ev_async *w)
1187 CODE:
1188 RETVAL = boolSV (ev_async_pending (w));
1189 OUTPUT:
1190 RETVAL
1191
1120MODULE = EV PACKAGE = EV::Loop PREFIX = ev_loop_ 1192MODULE = EV PACKAGE = EV::Loop PREFIX = ev_
1121 1193
1122SV *new (SV *klass, unsigned int flags = ev_supported_backends ()) 1194SV *new (SV *klass, unsigned int flags = 0)
1123 CODE: 1195 CODE:
1124{ 1196{
1125 struct ev_loop *loop = ev_loop_new (flags); 1197 struct ev_loop *loop = ev_loop_new (flags);
1126 1198
1127 if (!loop) 1199 if (!loop)
1134 1206
1135void DESTROY (struct ev_loop *loop) 1207void DESTROY (struct ev_loop *loop)
1136 CODE: 1208 CODE:
1137 if (loop != evapi.default_loop) /* global destruction sucks */ 1209 if (loop != evapi.default_loop) /* global destruction sucks */
1138 ev_loop_destroy (loop); 1210 ev_loop_destroy (loop);
1211
1212void ev_loop_fork (struct ev_loop *loop)
1213
1214void ev_loop_verify (struct ev_loop *loop)
1215
1216NV ev_now (struct ev_loop *loop)
1217
1218void ev_now_update (struct ev_loop *loop)
1219
1220void ev_set_io_collect_interval (struct ev_loop *loop, NV interval)
1221
1222void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval)
1223
1224unsigned int ev_backend (struct ev_loop *loop)
1225
1226unsigned int ev_loop_count (struct ev_loop *loop)
1227
1228void ev_loop (struct ev_loop *loop, int flags = 0)
1229
1230void ev_unloop (struct ev_loop *loop, int how = 1)
1231
1232void ev_feed_fd_event (struct ev_loop *loop, int fd, int revents = EV_NONE)
1233
1234#if 0
1235
1236void ev_feed_signal_event (struct ev_loop *loop, SV *signal)
1237 CODE:
1238{
1239 Signal signum = sv_signum (signal);
1240 CHECK_SIG (signal, signum);
1241
1242 ev_feed_signal_event (loop, signum);
1243}
1244
1245#endif
1139 1246
1140ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb) 1247ev_io *io (struct ev_loop *loop, SV *fh, int events, SV *cb)
1141 ALIAS: 1248 ALIAS:
1142 io_ns = 1 1249 io_ns = 1
1143 CODE: 1250 CODE:
1151 if (!ix) START (io, RETVAL); 1258 if (!ix) START (io, RETVAL);
1152} 1259}
1153 OUTPUT: 1260 OUTPUT:
1154 RETVAL 1261 RETVAL
1155 1262
1263ev_timer *timer (struct ev_loop *loop, NV after, NV repeat, SV *cb)
1264 ALIAS:
1265 timer_ns = 1
1266 INIT:
1267 CHECK_REPEAT (repeat);
1268 CODE:
1269 RETVAL = e_new (sizeof (ev_timer), cb, ST (0));
1270 ev_timer_set (RETVAL, after, repeat);
1271 if (!ix) START (timer, RETVAL);
1272 OUTPUT:
1273 RETVAL
1274
1275SV *periodic (struct ev_loop *loop, NV at, NV interval, SV *reschedule_cb, SV *cb)
1276 ALIAS:
1277 periodic_ns = 1
1278 INIT:
1279 CHECK_REPEAT (interval);
1280 CODE:
1281{
1282 ev_periodic *w;
1283 w = e_new (sizeof (ev_periodic), cb, ST (0));
1284 w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0;
1285 ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0);
1286 RETVAL = e_bless ((ev_watcher *)w, stash_periodic);
1287 if (!ix) START (periodic, w);
1288}
1289 OUTPUT:
1290 RETVAL
1291
1292#if 0
1293
1294ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb)
1295 ALIAS:
1296 signal_ns = 1
1297 CODE:
1298{
1299 Signal signum = sv_signum (signal);
1300 CHECK_SIG (signal, signum);
1301
1302 RETVAL = e_new (sizeof (ev_signal), cb, ST (0));
1303 ev_signal_set (RETVAL, signum);
1304 if (!ix) START (signal, RETVAL);
1305}
1306 OUTPUT:
1307 RETVAL
1308
1309#endif
1310
1311ev_idle *idle (struct ev_loop *loop, SV *cb)
1312 ALIAS:
1313 idle_ns = 1
1314 CODE:
1315 RETVAL = e_new (sizeof (ev_idle), cb, ST (0));
1316 ev_idle_set (RETVAL);
1317 if (!ix) START (idle, RETVAL);
1318 OUTPUT:
1319 RETVAL
1320
1321ev_prepare *prepare (struct ev_loop *loop, SV *cb)
1322 ALIAS:
1323 prepare_ns = 1
1324 CODE:
1325 RETVAL = e_new (sizeof (ev_prepare), cb, ST (0));
1326 ev_prepare_set (RETVAL);
1327 if (!ix) START (prepare, RETVAL);
1328 OUTPUT:
1329 RETVAL
1330
1331ev_check *check (struct ev_loop *loop, SV *cb)
1332 ALIAS:
1333 check_ns = 1
1334 CODE:
1335 RETVAL = e_new (sizeof (ev_check), cb, ST (0));
1336 ev_check_set (RETVAL);
1337 if (!ix) START (check, RETVAL);
1338 OUTPUT:
1339 RETVAL
1340
1341ev_fork *fork (struct ev_loop *loop, SV *cb)
1342 ALIAS:
1343 fork_ns = 1
1344 CODE:
1345 RETVAL = e_new (sizeof (ev_fork), cb, ST (0));
1346 ev_fork_set (RETVAL);
1347 if (!ix) START (fork, RETVAL);
1348 OUTPUT:
1349 RETVAL
1350
1351ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb)
1352 ALIAS:
1353 child_ns = 1
1354 CODE:
1355 RETVAL = e_new (sizeof (ev_child), cb, ST (0));
1356 ev_child_set (RETVAL, pid, trace);
1357 if (!ix) START (child, RETVAL);
1358 OUTPUT:
1359 RETVAL
1360
1361ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb)
1362 ALIAS:
1363 stat_ns = 1
1364 CODE:
1365 RETVAL = e_new (sizeof (ev_stat), cb, ST (0));
1366 RETVAL->fh = newSVsv (path);
1367 ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval);
1368 if (!ix) START (stat, RETVAL);
1369 OUTPUT:
1370 RETVAL
1371
1372ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0)
1373 ALIAS:
1374 embed_ns = 1
1375 CODE:
1376{
1377 if (!(ev_backend (other) & ev_embeddable_backends ()))
1378 croak ("passed loop is not embeddable via EV::embed,");
1379
1380 RETVAL = e_new (sizeof (ev_embed), cb, ST (0));
1381 RETVAL->fh = newSVsv (ST (1));
1382 ev_embed_set (RETVAL, other);
1383 if (!ix) START (embed, RETVAL);
1384}
1385 OUTPUT:
1386 RETVAL
1387
1388ev_async *async (struct ev_loop *loop, SV *cb)
1389 ALIAS:
1390 async_ns = 1
1391 CODE:
1392 RETVAL = e_new (sizeof (ev_async), cb, ST (0));
1393 ev_async_set (RETVAL);
1394 if (!ix) START (async, RETVAL);
1395 OUTPUT:
1396 RETVAL
1397
1398void once (struct ev_loop *loop, SV *fh, int events, SV *timeout, SV *cb)
1399 CODE:
1400 ev_once (
1401 loop,
1402 sv_fileno (fh), events,
1403 SvOK (timeout) ? SvNV (timeout) : -1.,
1404 e_once_cb,
1405 newSVsv (cb)
1406 );
1407

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines