1 | #include "EXTERN.h" |
1 | #include "EXTERN.h" |
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 | |
|
|
7 | /* fix perl api breakage */ |
|
|
8 | #undef signal |
|
|
9 | #undef sigaction |
6 | |
10 | |
7 | #define EV_PROTOTYPES 1 |
11 | #define EV_PROTOTYPES 1 |
8 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
12 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
9 | #define EV_H <ev.h> |
13 | #define EV_H <ev.h> |
10 | #include "EV/EVAPI.h" |
14 | #include "EV/EVAPI.h" |
11 | |
|
|
12 | /* fix perl api breakage */ |
|
|
13 | #undef signal |
|
|
14 | #undef sigaction |
|
|
15 | |
15 | |
16 | #define EV_SELECT_IS_WINSOCKET 0 |
16 | #define EV_SELECT_IS_WINSOCKET 0 |
17 | #ifdef _WIN32 |
17 | #ifdef _WIN32 |
18 | # define EV_SELECT_USE_FD_SET 0 |
18 | # define EV_SELECT_USE_FD_SET 0 |
19 | # define NFDBITS PERL_NFDBITS |
19 | # define NFDBITS PERL_NFDBITS |
… | |
… | |
127 | return SvIV (fh); |
127 | return SvIV (fh); |
128 | |
128 | |
129 | return -1; |
129 | return -1; |
130 | } |
130 | } |
131 | |
131 | |
|
|
132 | static SV * |
|
|
133 | e_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 | |
132 | static void * |
145 | static void * |
133 | e_new (int size, SV *cb_sv, SV *loop) |
146 | e_new (int size, SV *cb_sv, SV *loop) |
134 | { |
147 | { |
|
|
148 | SV *cv = cb_sv ? e_get_cv (cb_sv) : 0; |
135 | ev_watcher *w; |
149 | ev_watcher *w; |
136 | SV *self = NEWSV (0, size); |
150 | SV *self = NEWSV (0, size); |
137 | SvPOK_only (self); |
151 | SvPOK_only (self); |
138 | SvCUR_set (self, size); |
152 | SvCUR_set (self, size); |
139 | |
153 | |
140 | w = (ev_watcher *)SvPVX (self); |
154 | w = (ev_watcher *)SvPVX (self); |
141 | |
155 | |
142 | ev_init (w, e_cb); |
156 | ev_init (w, cv ? e_cb : 0); |
143 | |
157 | |
144 | w->loop = SvREFCNT_inc (SvRV (loop)); |
158 | w->loop = SvREFCNT_inc (SvRV (loop)); |
145 | w->e_flags = WFLAG_KEEPALIVE; |
159 | w->e_flags = WFLAG_KEEPALIVE; |
146 | w->data = 0; |
160 | w->data = 0; |
147 | w->fh = 0; |
161 | w->fh = 0; |
148 | w->cb_sv = SvTEMP (cb_sv) && SvREFCNT (cb_sv) == 1 ? SvREFCNT_inc (cb_sv) : newSVsv (cb_sv); |
162 | w->cb_sv = SvREFCNT_inc (cv); |
149 | w->self = self; |
163 | w->self = self; |
150 | |
164 | |
151 | return (void *)w; |
165 | return (void *)w; |
152 | } |
166 | } |
153 | |
167 | |
… | |
… | |
390 | evapi.sv_fileno = sv_fileno; |
404 | evapi.sv_fileno = sv_fileno; |
391 | evapi.sv_signum = sv_signum; |
405 | evapi.sv_signum = sv_signum; |
392 | evapi.supported_backends = ev_supported_backends (); |
406 | evapi.supported_backends = ev_supported_backends (); |
393 | evapi.recommended_backends = ev_recommended_backends (); |
407 | evapi.recommended_backends = ev_recommended_backends (); |
394 | evapi.embeddable_backends = ev_embeddable_backends (); |
408 | evapi.embeddable_backends = ev_embeddable_backends (); |
395 | evapi.time = ev_time; |
409 | evapi.time_ = ev_time; |
396 | evapi.sleep = ev_sleep; |
410 | evapi.sleep_ = ev_sleep; |
397 | evapi.loop_new = ev_loop_new; |
411 | evapi.loop_new = ev_loop_new; |
398 | evapi.loop_destroy = ev_loop_destroy; |
412 | evapi.loop_destroy = ev_loop_destroy; |
399 | evapi.loop_fork = ev_loop_fork; |
413 | evapi.loop_fork = ev_loop_fork; |
400 | evapi.loop_count = ev_loop_count; |
414 | evapi.loop_count = ev_loop_count; |
401 | evapi.now = ev_now; |
415 | evapi.now = ev_now; |
|
|
416 | evapi.now_update = ev_now_update; |
402 | evapi.backend = ev_backend; |
417 | evapi.backend = ev_backend; |
403 | evapi.unloop = ev_unloop; |
418 | evapi.unloop = ev_unloop; |
404 | evapi.ref = ev_ref; |
419 | evapi.ref = ev_ref; |
405 | evapi.unref = ev_unref; |
420 | evapi.unref = ev_unref; |
406 | evapi.loop = ev_loop; |
421 | evapi.loop = ev_loop; |
… | |
… | |
477 | NV ev_time () |
492 | NV ev_time () |
478 | |
493 | |
479 | NV ev_now () |
494 | NV ev_now () |
480 | C_ARGS: evapi.default_loop |
495 | C_ARGS: evapi.default_loop |
481 | |
496 | |
|
|
497 | void ev_now_update () |
|
|
498 | C_ARGS: evapi.default_loop |
|
|
499 | |
482 | unsigned int ev_backend () |
500 | unsigned int ev_backend () |
483 | C_ARGS: evapi.default_loop |
501 | C_ARGS: evapi.default_loop |
484 | |
502 | |
485 | unsigned int ev_loop_count () |
503 | unsigned int ev_loop_count () |
486 | C_ARGS: evapi.default_loop |
504 | C_ARGS: evapi.default_loop |
… | |
… | |
628 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
646 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
629 | if (!ix) START (stat, RETVAL); |
647 | if (!ix) START (stat, RETVAL); |
630 | OUTPUT: |
648 | OUTPUT: |
631 | RETVAL |
649 | RETVAL |
632 | |
650 | |
633 | ev_embed *embed (struct ev_loop *loop, SV *cb = &PL_sv_undef) |
651 | ev_embed *embed (struct ev_loop *loop, SV *cb = 0) |
634 | ALIAS: |
652 | ALIAS: |
635 | embed_ns = 1 |
653 | embed_ns = 1 |
636 | CODE: |
654 | CODE: |
637 | { |
655 | { |
638 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
656 | if (!(ev_backend (loop) & ev_embeddable_backends ())) |
639 | croak ("passed loop is not embeddable via EV::embed,"); |
657 | croak ("passed loop is not embeddable via EV::embed,"); |
640 | |
658 | |
641 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
659 | RETVAL = e_new (sizeof (ev_embed), cb, default_loop_sv); |
642 | RETVAL->fh = newSVsv (ST (0)); |
660 | RETVAL->fh = newSVsv (ST (0)); |
643 | ev_embed_set (RETVAL, loop); |
661 | ev_embed_set (RETVAL, loop); |
644 | |
|
|
645 | if (!SvOK (cb)) ev_set_cb (RETVAL, 0); |
|
|
646 | |
|
|
647 | if (!ix) START (embed, RETVAL); |
662 | if (!ix) START (embed, RETVAL); |
648 | } |
663 | } |
649 | OUTPUT: |
664 | OUTPUT: |
650 | RETVAL |
665 | RETVAL |
651 | |
666 | |
… | |
… | |
703 | RETVAL |
718 | RETVAL |
704 | |
719 | |
705 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
720 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
706 | CODE: |
721 | CODE: |
707 | { |
722 | { |
708 | RETVAL = newSVsv (w->cb_sv); |
|
|
709 | |
|
|
710 | if (items > 1) |
723 | if (items > 1) |
711 | 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); |
712 | } |
731 | } |
713 | OUTPUT: |
732 | OUTPUT: |
714 | RETVAL |
733 | RETVAL |
715 | |
734 | |
716 | SV *data (ev_watcher *w, SV *new_data = 0) |
735 | SV *data (ev_watcher *w, SV *new_data = 0) |
… | |
… | |
889 | INIT: |
908 | INIT: |
890 | CHECK_REPEAT (repeat); |
909 | CHECK_REPEAT (repeat); |
891 | CODE: |
910 | CODE: |
892 | RESET (timer, w, (w, after, repeat)); |
911 | RESET (timer, w, (w, after, repeat)); |
893 | |
912 | |
894 | NV at (ev_timer *w) |
|
|
895 | CODE: |
|
|
896 | RETVAL = w->at; |
|
|
897 | OUTPUT: |
|
|
898 | RETVAL |
|
|
899 | |
|
|
900 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
913 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
901 | |
914 | |
902 | void ev_periodic_start (ev_periodic *w) |
915 | void ev_periodic_start (ev_periodic *w) |
903 | INIT: |
916 | INIT: |
904 | CHECK_REPEAT (w->interval); |
917 | CHECK_REPEAT (w->interval); |
… | |
… | |
931 | 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)); |
932 | } |
945 | } |
933 | |
946 | |
934 | NV at (ev_periodic *w) |
947 | NV at (ev_periodic *w) |
935 | CODE: |
948 | CODE: |
936 | RETVAL = w->at; |
949 | RETVAL = ev_periodic_at (w); |
937 | OUTPUT: |
950 | OUTPUT: |
938 | RETVAL |
951 | RETVAL |
939 | |
952 | |
940 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
953 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
941 | |
954 | |
… | |
… | |
1168 | e_destroy (w); |
1181 | e_destroy (w); |
1169 | |
1182 | |
1170 | void ev_async_send (ev_async *w) |
1183 | void ev_async_send (ev_async *w) |
1171 | C_ARGS: e_loop (w), w |
1184 | C_ARGS: e_loop (w), w |
1172 | |
1185 | |
|
|
1186 | SV *ev_async_async_pending (ev_async *w) |
|
|
1187 | CODE: |
|
|
1188 | RETVAL = boolSV (ev_async_pending (w)); |
|
|
1189 | OUTPUT: |
|
|
1190 | RETVAL |
|
|
1191 | |
1173 | MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ |
1192 | MODULE = EV PACKAGE = EV::Loop PREFIX = ev_ |
1174 | |
1193 | |
1175 | SV *new (SV *klass, unsigned int flags = 0) |
1194 | SV *new (SV *klass, unsigned int flags = 0) |
1176 | CODE: |
1195 | CODE: |
1177 | { |
1196 | { |
… | |
… | |
1190 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1209 | if (loop != evapi.default_loop) /* global destruction sucks */ |
1191 | ev_loop_destroy (loop); |
1210 | ev_loop_destroy (loop); |
1192 | |
1211 | |
1193 | void ev_loop_fork (struct ev_loop *loop) |
1212 | void ev_loop_fork (struct ev_loop *loop) |
1194 | |
1213 | |
|
|
1214 | void ev_loop_verify (struct ev_loop *loop) |
|
|
1215 | |
1195 | NV ev_now (struct ev_loop *loop) |
1216 | NV ev_now (struct ev_loop *loop) |
|
|
1217 | |
|
|
1218 | void ev_now_update (struct ev_loop *loop) |
1196 | |
1219 | |
1197 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1220 | void ev_set_io_collect_interval (struct ev_loop *loop, NV interval) |
1198 | |
1221 | |
1199 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1222 | void ev_set_timeout_collect_interval (struct ev_loop *loop, NV interval) |
1200 | |
1223 | |
… | |
… | |
1344 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
1367 | ev_stat_set (RETVAL, SvPVbyte_nolen (RETVAL->fh), interval); |
1345 | if (!ix) START (stat, RETVAL); |
1368 | if (!ix) START (stat, RETVAL); |
1346 | OUTPUT: |
1369 | OUTPUT: |
1347 | RETVAL |
1370 | RETVAL |
1348 | |
1371 | |
1349 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = &PL_sv_undef) |
1372 | ev_embed *embed (struct ev_loop *loop, struct ev_loop *other, SV *cb = 0) |
1350 | ALIAS: |
1373 | ALIAS: |
1351 | embed_ns = 1 |
1374 | embed_ns = 1 |
1352 | CODE: |
1375 | CODE: |
1353 | { |
1376 | { |
1354 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
1377 | if (!(ev_backend (other) & ev_embeddable_backends ())) |
1355 | croak ("passed loop is not embeddable via EV::embed,"); |
1378 | croak ("passed loop is not embeddable via EV::embed,"); |
1356 | |
1379 | |
1357 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
1380 | RETVAL = e_new (sizeof (ev_embed), cb, ST (0)); |
1358 | RETVAL->fh = newSVsv (ST (1)); |
1381 | RETVAL->fh = newSVsv (ST (1)); |
1359 | ev_embed_set (RETVAL, other); |
1382 | ev_embed_set (RETVAL, other); |
1360 | |
|
|
1361 | if (!SvOK (cb)) ev_set_cb (RETVAL, 0); |
|
|
1362 | |
|
|
1363 | if (!ix) START (embed, RETVAL); |
1383 | if (!ix) START (embed, RETVAL); |
1364 | } |
1384 | } |
1365 | OUTPUT: |
1385 | OUTPUT: |
1366 | RETVAL |
1386 | RETVAL |
1367 | |
1387 | |