… | |
… | |
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 |
7 | #define EV_PROTOTYPES 1 |
|
|
8 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
8 | #define EV_H <ev.h> |
9 | #define EV_H <ev.h> |
9 | #include "EV/EVAPI.h" |
10 | #include "EV/EVAPI.h" |
10 | |
11 | |
11 | /* fix perl api breakage */ |
12 | /* fix perl api breakage */ |
12 | #undef signal |
13 | #undef signal |
… | |
… | |
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); \ |
… | |
… | |
137 | |
138 | |
138 | w = (ev_watcher *)SvPVX (self); |
139 | w = (ev_watcher *)SvPVX (self); |
139 | |
140 | |
140 | ev_init (w, e_cb); |
141 | ev_init (w, e_cb); |
141 | |
142 | |
142 | w->loop = SvREFCNT_inc (SvRV (loop)); |
143 | w->loop = SvREFCNT_inc (SvRV (loop)); |
143 | w->flags = WFLAG_KEEPALIVE; |
144 | w->e_flags = WFLAG_KEEPALIVE; |
144 | w->data = 0; |
145 | w->data = 0; |
145 | w->fh = 0; |
146 | w->fh = 0; |
146 | w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); |
147 | w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); |
147 | w->self = self; |
148 | w->self = self; |
148 | |
149 | |
149 | return (void *)w; |
150 | return (void *)w; |
150 | } |
151 | } |
151 | |
152 | |
152 | static void |
153 | static void |
… | |
… | |
388 | evapi.sv_signum = sv_signum; |
389 | evapi.sv_signum = sv_signum; |
389 | evapi.supported_backends = ev_supported_backends (); |
390 | evapi.supported_backends = ev_supported_backends (); |
390 | evapi.recommended_backends = ev_recommended_backends (); |
391 | evapi.recommended_backends = ev_recommended_backends (); |
391 | evapi.embeddable_backends = ev_embeddable_backends (); |
392 | evapi.embeddable_backends = ev_embeddable_backends (); |
392 | evapi.time = ev_time; |
393 | evapi.time = ev_time; |
|
|
394 | evapi.sleep = ev_sleep; |
393 | evapi.loop_new = ev_loop_new; |
395 | evapi.loop_new = ev_loop_new; |
394 | evapi.loop_destroy = ev_loop_destroy; |
396 | evapi.loop_destroy = ev_loop_destroy; |
395 | evapi.loop_fork = ev_loop_fork; |
397 | evapi.loop_fork = ev_loop_fork; |
396 | evapi.loop_count = ev_loop_count; |
398 | evapi.loop_count = ev_loop_count; |
397 | evapi.now = ev_now; |
399 | evapi.now = ev_now; |
… | |
… | |
453 | RETVAL = newSVsv (default_loop_sv); |
455 | RETVAL = newSVsv (default_loop_sv); |
454 | } |
456 | } |
455 | OUTPUT: |
457 | OUTPUT: |
456 | RETVAL |
458 | RETVAL |
457 | |
459 | |
|
|
460 | void ev_default_destroy () |
|
|
461 | CODE: |
|
|
462 | ev_default_destroy (); |
|
|
463 | SvREFCNT_dec (default_loop_sv); |
|
|
464 | default_loop_sv = 0; |
|
|
465 | |
|
|
466 | unsigned int ev_supported_backends () |
|
|
467 | |
|
|
468 | unsigned int ev_recommended_backends () |
|
|
469 | |
|
|
470 | unsigned int ev_embeddable_backends () |
|
|
471 | |
458 | NV ev_time () |
472 | NV ev_time () |
459 | |
473 | |
460 | NV ev_now () |
474 | NV ev_now () |
461 | C_ARGS: evapi.default_loop |
475 | C_ARGS: evapi.default_loop |
462 | |
476 | |
… | |
… | |
464 | C_ARGS: evapi.default_loop |
478 | C_ARGS: evapi.default_loop |
465 | |
479 | |
466 | unsigned int ev_loop_count () |
480 | unsigned int ev_loop_count () |
467 | C_ARGS: evapi.default_loop |
481 | C_ARGS: evapi.default_loop |
468 | |
482 | |
|
|
483 | void ev_set_io_collect_interval (NV interval) |
|
|
484 | C_ARGS: evapi.default_loop, interval |
|
|
485 | |
|
|
486 | void ev_set_timeout_collect_interval (NV interval) |
|
|
487 | C_ARGS: evapi.default_loop, interval |
|
|
488 | |
469 | void ev_loop (int flags = 0) |
489 | void ev_loop (int flags = 0) |
470 | C_ARGS: evapi.default_loop, flags |
490 | C_ARGS: evapi.default_loop, flags |
471 | |
491 | |
472 | void ev_unloop (int how = 1) |
492 | void ev_unloop (int how = EVUNLOOP_ONE) |
473 | C_ARGS: evapi.default_loop, how |
493 | C_ARGS: evapi.default_loop, how |
474 | |
494 | |
475 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
495 | void ev_feed_fd_event (int fd, int revents = EV_NONE) |
476 | C_ARGS: evapi.default_loop, fd, revents |
496 | C_ARGS: evapi.default_loop, fd, revents |
477 | |
497 | |
… | |
… | |
582 | ev_fork_set (RETVAL); |
602 | ev_fork_set (RETVAL); |
583 | if (!ix) START (fork, RETVAL); |
603 | if (!ix) START (fork, RETVAL); |
584 | OUTPUT: |
604 | OUTPUT: |
585 | RETVAL |
605 | RETVAL |
586 | |
606 | |
587 | ev_child *child (int pid, SV *cb) |
607 | ev_child *child (int pid, int trace, SV *cb) |
588 | ALIAS: |
608 | ALIAS: |
589 | child_ns = 1 |
609 | child_ns = 1 |
590 | CODE: |
610 | CODE: |
591 | RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); |
611 | RETVAL = e_new (sizeof (ev_child), cb, default_loop_sv); |
592 | ev_child_set (RETVAL, pid); |
612 | ev_child_set (RETVAL, pid, trace); |
593 | if (!ix) START (child, RETVAL); |
613 | if (!ix) START (child, RETVAL); |
594 | OUTPUT: |
614 | OUTPUT: |
595 | RETVAL |
615 | RETVAL |
596 | |
616 | |
597 | ev_stat *stat (SV *path, NV interval, SV *cb) |
617 | ev_stat *stat (SV *path, NV interval, SV *cb) |
… | |
… | |
652 | C_ARGS: e_loop (w), w, revents |
672 | C_ARGS: e_loop (w), w, revents |
653 | |
673 | |
654 | int keepalive (ev_watcher *w, int new_value = 0) |
674 | int keepalive (ev_watcher *w, int new_value = 0) |
655 | CODE: |
675 | CODE: |
656 | { |
676 | { |
657 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
677 | RETVAL = w->e_flags & WFLAG_KEEPALIVE; |
658 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
678 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
659 | |
679 | |
660 | if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) |
680 | if (items > 1 && ((new_value ^ w->e_flags) & WFLAG_KEEPALIVE)) |
661 | { |
681 | { |
662 | REF (w); |
682 | REF (w); |
663 | w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; |
683 | w->e_flags = (w->e_flags & ~WFLAG_KEEPALIVE) | new_value; |
664 | UNREF (w); |
684 | UNREF (w); |
665 | } |
685 | } |
666 | } |
686 | } |
667 | OUTPUT: |
687 | OUTPUT: |
668 | RETVAL |
688 | RETVAL |
… | |
… | |
915 | void DESTROY (ev_idle *w) |
935 | void DESTROY (ev_idle *w) |
916 | CODE: |
936 | CODE: |
917 | STOP (idle, w); |
937 | STOP (idle, w); |
918 | e_destroy (w); |
938 | e_destroy (w); |
919 | |
939 | |
920 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
940 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_prepare_ |
921 | |
941 | |
922 | void ev_prepare_start (ev_prepare *w) |
942 | void ev_prepare_start (ev_prepare *w) |
923 | CODE: |
943 | CODE: |
924 | START (prepare, w); |
944 | START (prepare, w); |
925 | |
945 | |
… | |
… | |
975 | void DESTROY (ev_child *w) |
995 | void DESTROY (ev_child *w) |
976 | CODE: |
996 | CODE: |
977 | STOP (child, w); |
997 | STOP (child, w); |
978 | e_destroy (w); |
998 | e_destroy (w); |
979 | |
999 | |
980 | void set (ev_child *w, int pid) |
1000 | void set (ev_child *w, int pid, int trace) |
981 | CODE: |
1001 | CODE: |
982 | RESET (child, w, (w, pid)); |
1002 | RESET (child, w, (w, pid, trace)); |
983 | |
1003 | |
984 | int pid (ev_child *w, int new_pid = 0) |
|
|
985 | CODE: |
|
|
986 | { |
|
|
987 | RETVAL = w->pid; |
|
|
988 | |
|
|
989 | if (items > 1) |
|
|
990 | RESET (child, w, (w, new_pid)); |
|
|
991 | } |
|
|
992 | OUTPUT: |
|
|
993 | RETVAL |
|
|
994 | |
|
|
995 | |
|
|
996 | int rstatus (ev_child *w) |
1004 | int pid (ev_child *w) |
997 | ALIAS: |
1005 | ALIAS: |
998 | rpid = 1 |
1006 | rpid = 1 |
|
|
1007 | rstatus = 2 |
999 | CODE: |
1008 | CODE: |
1000 | RETVAL = ix ? w->rpid : w->rstatus; |
1009 | RETVAL = ix == 0 ? w->pid |
|
|
1010 | : ix == 1 ? w->rpid |
|
|
1011 | : w->rstatus; |
1001 | OUTPUT: |
1012 | OUTPUT: |
1002 | RETVAL |
1013 | RETVAL |
1003 | |
1014 | |
1004 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
1015 | MODULE = EV PACKAGE = EV::Stat PREFIX = ev_stat_ |
1005 | |
1016 | |
… | |
… | |
1145 | |
1156 | |
1146 | void ev_loop_fork (struct ev_loop *loop) |
1157 | void ev_loop_fork (struct ev_loop *loop) |
1147 | |
1158 | |
1148 | NV ev_now (struct ev_loop *loop) |
1159 | NV ev_now (struct ev_loop *loop) |
1149 | |
1160 | |
|
|
1161 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1162 | |
|
|
1163 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
|
|
1164 | |
1150 | unsigned int ev_backend (struct ev_loop *loop) |
1165 | unsigned int ev_backend (struct ev_loop *loop) |
1151 | |
1166 | |
1152 | unsigned int ev_loop_count (struct ev_loop *loop) |
1167 | unsigned int ev_loop_count (struct ev_loop *loop) |
1153 | |
1168 | |
1154 | void ev_loop (struct ev_loop *loop, int flags = 0) |
1169 | void ev_loop (struct ev_loop *loop, int flags = 0) |
… | |
… | |
1272 | ev_fork_set (RETVAL); |
1287 | ev_fork_set (RETVAL); |
1273 | if (!ix) START (fork, RETVAL); |
1288 | if (!ix) START (fork, RETVAL); |
1274 | OUTPUT: |
1289 | OUTPUT: |
1275 | RETVAL |
1290 | RETVAL |
1276 | |
1291 | |
1277 | ev_child *child (struct ev_loop *loop, int pid, SV *cb) |
1292 | ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) |
1278 | ALIAS: |
1293 | ALIAS: |
1279 | child_ns = 1 |
1294 | child_ns = 1 |
1280 | CODE: |
1295 | CODE: |
1281 | RETVAL = e_new (sizeof (ev_child), cb, ST (0)); |
1296 | RETVAL = e_new (sizeof (ev_child), cb, ST (0)); |
1282 | ev_child_set (RETVAL, pid); |
1297 | ev_child_set (RETVAL, pid, trace); |
1283 | if (!ix) START (child, RETVAL); |
1298 | if (!ix) START (child, RETVAL); |
1284 | OUTPUT: |
1299 | OUTPUT: |
1285 | RETVAL |
1300 | RETVAL |
1286 | |
1301 | |
1287 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |
1302 | ev_stat *stat (struct ev_loop *loop, SV *path, NV interval, SV *cb) |