… | |
… | |
13 | sv_fileno (SV *fh) |
13 | sv_fileno (SV *fh) |
14 | { |
14 | { |
15 | return s_fileno (fh, 0); |
15 | return s_fileno (fh, 0); |
16 | } |
16 | } |
17 | |
17 | |
|
|
18 | #ifndef GvCV_set |
|
|
19 | # define GvCV_set(gv,cv) GvCV (gv) = cv |
|
|
20 | #endif |
|
|
21 | |
18 | #define EV_STANDALONE 1 |
22 | #define EV_STANDALONE 1 |
19 | #define EV_PROTOTYPES 1 |
23 | #define EV_PROTOTYPES 1 |
20 | #define EV_USE_CLOCK_SYSCALL 0 /* as long as we need pthreads anyways... */ |
|
|
21 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
24 | #define EV_USE_NANOSLEEP EV_USE_MONOTONIC |
22 | #define EV_USE_FLOOR 1 |
25 | #define EV_USE_FLOOR 1 |
|
|
26 | #define EV_API_STATIC |
23 | #define EV_H <ev.h> |
27 | #define EV_H <ev.h> |
24 | #define EV_CONFIG_H error |
28 | #define EV_CONFIG_H error |
25 | #include "EV/EVAPI.h" |
29 | #include "EV/EVAPI.h" |
26 | |
30 | |
27 | #define EV_SELECT_IS_WINSOCKET 0 |
31 | #define EV_SELECT_IS_WINSOCKET 0 |
… | |
… | |
31 | # define fd_mask Perl_fd_mask |
35 | # define fd_mask Perl_fd_mask |
32 | #endif |
36 | #endif |
33 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
37 | /* due to bugs in OS X we have to use libev/ explicitly here */ |
34 | #include "libev/ev.c" |
38 | #include "libev/ev.c" |
35 | |
39 | |
36 | #if !defined(_WIN32) && !defined(_MINIX) |
40 | #if !defined _WIN32 && !defined _MINIX |
37 | # include <pthread.h> |
41 | # include <pthread.h> |
38 | #endif |
42 | #endif |
39 | |
43 | |
40 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
44 | #define e_loop(w) INT2PTR (struct ev_loop *, SvIVX (((ev_watcher *)(w))->loop)) |
41 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
45 | #define e_flags(w) ((ev_watcher *)(w))->e_flags |
… | |
… | |
381 | const_iv (EV_, SIGNAL) |
385 | const_iv (EV_, SIGNAL) |
382 | const_iv (EV_, CHILD) |
386 | const_iv (EV_, CHILD) |
383 | const_iv (EV_, STAT) |
387 | const_iv (EV_, STAT) |
384 | const_iv (EV_, IDLE) |
388 | const_iv (EV_, IDLE) |
385 | const_iv (EV_, PREPARE) |
389 | const_iv (EV_, PREPARE) |
386 | const_iv (EV_, CHECK) |
390 | /*const_iv (EV_, CHECK) needs special tretament */ |
387 | const_iv (EV_, EMBED) |
391 | const_iv (EV_, EMBED) |
388 | const_iv (EV_, FORK) |
392 | const_iv (EV_, FORK) |
389 | const_iv (EV_, CLEANUP) |
393 | const_iv (EV_, CLEANUP) |
390 | const_iv (EV_, ASYNC) |
394 | const_iv (EV_, ASYNC) |
391 | const_iv (EV_, CUSTOM) |
395 | const_iv (EV_, CUSTOM) |
… | |
… | |
423 | const_iv (EV, UNLOOP_ONE) |
427 | const_iv (EV, UNLOOP_ONE) |
424 | const_iv (EV, UNLOOP_ALL) |
428 | const_iv (EV, UNLOOP_ALL) |
425 | #endif |
429 | #endif |
426 | }; |
430 | }; |
427 | |
431 | |
428 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
432 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
429 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
433 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
|
|
434 | |
|
|
435 | /* since this clashes with perl CHECK blocks, */ |
|
|
436 | /* but we are interested in constants, */ |
|
|
437 | /* and not blocks, we treat CHECK specially. */ |
|
|
438 | { |
|
|
439 | /* the local $^W = 0 takes care of the warning */ |
|
|
440 | CV *cv = newCONSTSUB (stash, "CHECK", newSViv (EV_CHECK)); |
|
|
441 | /* now we need to re-set the gv, in case it was hijacked */ |
|
|
442 | GvCV_set (gv_fetchpv ("EV::CHECK", GV_ADD, SVt_PVCV), cv); |
|
|
443 | } |
430 | |
444 | |
431 | stash_loop = gv_stashpv ("EV::Loop" , 1); |
445 | stash_loop = gv_stashpv ("EV::Loop" , 1); |
432 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
446 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
433 | stash_io = gv_stashpv ("EV::IO" , 1); |
447 | stash_io = gv_stashpv ("EV::IO" , 1); |
434 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
448 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
… | |
… | |
517 | evapi.invoke = ev_invoke; |
531 | evapi.invoke = ev_invoke; |
518 | |
532 | |
519 | sv_setiv (sv, (IV)&evapi); |
533 | sv_setiv (sv, (IV)&evapi); |
520 | SvREADONLY_on (sv); |
534 | SvREADONLY_on (sv); |
521 | } |
535 | } |
522 | #if !defined(_WIN32) && !defined(_MINIX) |
536 | #if !defined _WIN32 && !defined _MINIX |
|
|
537 | #if __linux |
|
|
538 | int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle); |
|
|
539 | __register_atfork (0, 0, default_fork, 0); |
|
|
540 | #else |
523 | pthread_atfork (0, 0, default_fork); |
541 | pthread_atfork (0, 0, default_fork); |
|
|
542 | #endif |
524 | #endif |
543 | #endif |
525 | } |
544 | } |
526 | |
545 | |
527 | SV *ev_default_loop (unsigned int flags = 0) |
546 | SV *ev_default_loop (unsigned int flags = 0) |
528 | CODE: |
547 | CODE: |
… | |
… | |
601 | C_ARGS: evapi.default_loop, interval |
620 | C_ARGS: evapi.default_loop, interval |
602 | |
621 | |
603 | void ev_set_timeout_collect_interval (NV interval) |
622 | void ev_set_timeout_collect_interval (NV interval) |
604 | C_ARGS: evapi.default_loop, interval |
623 | C_ARGS: evapi.default_loop, interval |
605 | |
624 | |
606 | void ev_run (int flags = 0) |
625 | int ev_run (int flags = 0) |
607 | ALIAS: |
626 | ALIAS: |
608 | loop = 1 |
627 | loop = 1 |
609 | C_ARGS: evapi.default_loop, flags |
628 | C_ARGS: evapi.default_loop, flags |
610 | |
629 | |
611 | void ev_break (int how = EVBREAK_ONE) |
630 | void ev_break (int how = EVBREAK_ONE) |
… | |
… | |
617 | C_ARGS: evapi.default_loop, fd, revents |
636 | C_ARGS: evapi.default_loop, fd, revents |
618 | |
637 | |
619 | void ev_feed_signal_event (SV *signal) |
638 | void ev_feed_signal_event (SV *signal) |
620 | CODE: |
639 | CODE: |
621 | { |
640 | { |
622 | Signal signum = s_signum (signal); |
641 | Signal signum = s_signum (signal); |
623 | CHECK_SIG (signal, signum); |
642 | CHECK_SIG (signal, signum); |
624 | |
643 | |
625 | ev_feed_signal_event (evapi.default_loop, signum); |
644 | ev_feed_signal_event (evapi.default_loop, signum); |
626 | } |
645 | } |
627 | |
646 | |
… | |
… | |
736 | ev_fork_set (RETVAL); |
755 | ev_fork_set (RETVAL); |
737 | if (!ix) START (fork, RETVAL); |
756 | if (!ix) START (fork, RETVAL); |
738 | OUTPUT: |
757 | OUTPUT: |
739 | RETVAL |
758 | RETVAL |
740 | |
759 | |
|
|
760 | #if CLEANUP_ENABLED |
|
|
761 | |
741 | ev_cleanup *cleanup (SV *cb) |
762 | ev_cleanup *cleanup (SV *cb) |
742 | ALIAS: |
763 | ALIAS: |
743 | cleanup_ns = 1 |
764 | cleanup_ns = 1 |
744 | CODE: |
765 | CODE: |
745 | RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv); |
766 | RETVAL = e_new (sizeof (ev_cleanup), cb, default_loop_sv); |
|
|
767 | SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */ |
746 | ev_cleanup_set (RETVAL); |
768 | ev_cleanup_set (RETVAL); |
747 | if (!ix) START (cleanup, RETVAL); |
769 | if (!ix) START (cleanup, RETVAL); |
748 | OUTPUT: |
770 | OUTPUT: |
749 | RETVAL |
771 | RETVAL |
|
|
772 | |
|
|
773 | #endif |
750 | |
774 | |
751 | ev_child *child (int pid, int trace, SV *cb) |
775 | ev_child *child (int pid, int trace, SV *cb) |
752 | ALIAS: |
776 | ALIAS: |
753 | child_ns = 1 |
777 | child_ns = 1 |
754 | CODE: |
778 | CODE: |
… | |
… | |
1139 | void DESTROY (ev_fork *w) |
1163 | void DESTROY (ev_fork *w) |
1140 | CODE: |
1164 | CODE: |
1141 | STOP (fork, w); |
1165 | STOP (fork, w); |
1142 | e_destroy (w); |
1166 | e_destroy (w); |
1143 | |
1167 | |
|
|
1168 | #if CLEANUP_ENABLED |
|
|
1169 | |
1144 | MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_ |
1170 | MODULE = EV PACKAGE = EV::Cleanup PREFIX = ev_cleanup_ |
1145 | |
1171 | |
1146 | void ev_cleanup_start (ev_cleanup *w) |
1172 | void ev_cleanup_start (ev_cleanup *w) |
1147 | CODE: |
1173 | CODE: |
1148 | START (cleanup, w); |
1174 | START (cleanup, w); |
… | |
… | |
1152 | STOP (cleanup, w); |
1178 | STOP (cleanup, w); |
1153 | |
1179 | |
1154 | void DESTROY (ev_cleanup *w) |
1180 | void DESTROY (ev_cleanup *w) |
1155 | CODE: |
1181 | CODE: |
1156 | STOP (cleanup, w); |
1182 | STOP (cleanup, w); |
|
|
1183 | SvREFCNT_inc (w->loop); /* has been dec'ed on creation */ |
1157 | e_destroy (w); |
1184 | e_destroy (w); |
1158 | |
1185 | |
1159 | int keepalive (ev_watcher *w, int new_value = 0) |
1186 | int keepalive (ev_watcher *w, SV *new_value = 0) |
1160 | CODE: |
1187 | CODE: |
1161 | RETVAL = 0; |
1188 | RETVAL = 1; |
1162 | OUTPUT: |
1189 | OUTPUT: |
1163 | RETVAL |
1190 | RETVAL |
|
|
1191 | |
|
|
1192 | #endif |
1164 | |
1193 | |
1165 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
1194 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
1166 | |
1195 | |
1167 | #if EV_CHILD_ENABLE |
1196 | #if EV_CHILD_ENABLE |
1168 | |
1197 | |
… | |
… | |
1362 | OUTPUT: |
1391 | OUTPUT: |
1363 | RETVAL |
1392 | RETVAL |
1364 | |
1393 | |
1365 | void DESTROY (struct ev_loop *loop) |
1394 | void DESTROY (struct ev_loop *loop) |
1366 | CODE: |
1395 | CODE: |
1367 | /* 1. the default loop shouldn't be freed by destroying it'S pelr loop object */ |
1396 | /* 1. the default loop shouldn't be freed by destroying it's perl loop object */ |
1368 | /* 2. not doing so helps avoid many global destruction bugs in perl, too */ |
1397 | /* 2. not doing so helps avoid many global destruction bugs in perl, too */ |
1369 | if (loop != evapi.default_loop) |
1398 | if (loop != evapi.default_loop) |
1370 | ev_loop_destroy (loop); |
1399 | ev_loop_destroy (loop); |
1371 | |
1400 | |
1372 | void ev_loop_fork (struct ev_loop *loop) |
1401 | void ev_loop_fork (struct ev_loop *loop) |
… | |
… | |
1395 | |
1424 | |
1396 | unsigned int ev_depth (struct ev_loop *loop) |
1425 | unsigned int ev_depth (struct ev_loop *loop) |
1397 | ALIAS: |
1426 | ALIAS: |
1398 | loop_depth = 1 |
1427 | loop_depth = 1 |
1399 | |
1428 | |
1400 | void ev_run (struct ev_loop *loop, int flags = 0) |
1429 | int ev_run (struct ev_loop *loop, int flags = 0) |
1401 | ALIAS: |
1430 | ALIAS: |
1402 | loop = 1 |
1431 | loop = 1 |
1403 | |
1432 | |
1404 | void ev_break (struct ev_loop *loop, int how = 1) |
1433 | void ev_break (struct ev_loop *loop, int how = 1) |
1405 | ALIAS: |
1434 | ALIAS: |
… | |
… | |
1414 | #if 0 |
1443 | #if 0 |
1415 | |
1444 | |
1416 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1445 | void ev_feed_signal_event (struct ev_loop *loop, SV *signal) |
1417 | CODE: |
1446 | CODE: |
1418 | { |
1447 | { |
1419 | Signal signum = s_signum (signal); |
1448 | Signal signum = s_signum (signal); |
1420 | CHECK_SIG (signal, signum); |
1449 | CHECK_SIG (signal, signum); |
1421 | |
1450 | |
1422 | ev_feed_signal_event (loop, signum); |
1451 | ev_feed_signal_event (loop, signum); |
1423 | } |
1452 | } |
1424 | |
1453 | |
… | |
… | |
1457 | periodic_ns = 1 |
1486 | periodic_ns = 1 |
1458 | INIT: |
1487 | INIT: |
1459 | CHECK_REPEAT (interval); |
1488 | CHECK_REPEAT (interval); |
1460 | CODE: |
1489 | CODE: |
1461 | { |
1490 | { |
1462 | ev_periodic *w; |
1491 | ev_periodic *w; |
1463 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
1492 | w = e_new (sizeof (ev_periodic), cb, ST (0)); |
1464 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
1493 | e_fh (w) = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
1465 | ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); |
1494 | ev_periodic_set (w, at, interval, e_fh (w) ? e_periodic_cb : 0); |
1466 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
1495 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
1467 | if (!ix) START (periodic, w); |
1496 | if (!ix) START (periodic, w); |
… | |
… | |
1472 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1501 | ev_signal *signal (struct ev_loop *loop, SV *signal, SV *cb) |
1473 | ALIAS: |
1502 | ALIAS: |
1474 | signal_ns = 1 |
1503 | signal_ns = 1 |
1475 | CODE: |
1504 | CODE: |
1476 | { |
1505 | { |
1477 | Signal signum = s_signum (signal); |
1506 | Signal signum = s_signum (signal); |
1478 | CHECK_SIG (signal, signum); |
1507 | CHECK_SIG (signal, signum); |
1479 | |
1508 | |
1480 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1509 | RETVAL = e_new (sizeof (ev_signal), cb, ST (0)); |
1481 | ev_signal_set (RETVAL, signum); |
1510 | ev_signal_set (RETVAL, signum); |
1482 | if (!ix) START_SIGNAL (RETVAL); |
1511 | if (!ix) START_SIGNAL (RETVAL); |
… | |
… | |
1522 | ev_fork_set (RETVAL); |
1551 | ev_fork_set (RETVAL); |
1523 | if (!ix) START (fork, RETVAL); |
1552 | if (!ix) START (fork, RETVAL); |
1524 | OUTPUT: |
1553 | OUTPUT: |
1525 | RETVAL |
1554 | RETVAL |
1526 | |
1555 | |
|
|
1556 | #if CLEANUP_ENABLED |
|
|
1557 | |
1527 | ev_cleanup *cleanup (struct ev_loop *loop, SV *cb) |
1558 | ev_cleanup *cleanup (struct ev_loop *loop, SV *cb) |
1528 | ALIAS: |
1559 | ALIAS: |
1529 | cleanup_ns = 1 |
1560 | cleanup_ns = 1 |
1530 | CODE: |
1561 | CODE: |
1531 | RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0)); |
1562 | RETVAL = e_new (sizeof (ev_cleanup), cb, ST (0)); |
|
|
1563 | SvREFCNT_dec (RETVAL->loop); /* must not keep loop object alive */ |
1532 | ev_cleanup_set (RETVAL); |
1564 | ev_cleanup_set (RETVAL); |
1533 | if (!ix) START (cleanup, RETVAL); |
1565 | if (!ix) START (cleanup, RETVAL); |
1534 | OUTPUT: |
1566 | OUTPUT: |
1535 | RETVAL |
1567 | RETVAL |
|
|
1568 | |
|
|
1569 | #endif |
1536 | |
1570 | |
1537 | ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) |
1571 | ev_child *child (struct ev_loop *loop, int pid, int trace, SV *cb) |
1538 | ALIAS: |
1572 | ALIAS: |
1539 | child_ns = 1 |
1573 | child_ns = 1 |
1540 | CODE: |
1574 | CODE: |