… | |
… | |
35 | |
35 | |
36 | #ifndef _WIN32 |
36 | #ifndef _WIN32 |
37 | # include <pthread.h> |
37 | # include <pthread.h> |
38 | #endif |
38 | #endif |
39 | |
39 | |
|
|
40 | #define WFLAG_KEEPALIVE 1 |
|
|
41 | |
|
|
42 | #define UNREF(w) \ |
|
|
43 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
|
|
44 | && !ev_is_active (w)) \ |
|
|
45 | ev_unref (); |
|
|
46 | |
|
|
47 | #define REF(w) \ |
|
|
48 | if (!((w)->flags & WFLAG_KEEPALIVE) \ |
|
|
49 | && ev_is_active (w)) \ |
|
|
50 | ev_ref (); |
|
|
51 | |
|
|
52 | #define START(type,w) \ |
|
|
53 | do { \ |
|
|
54 | UNREF (w); \ |
|
|
55 | ev_ ## type ## _start (w); \ |
|
|
56 | } while (0) |
|
|
57 | |
|
|
58 | #define STOP(type,w) \ |
|
|
59 | do { \ |
|
|
60 | REF (w); \ |
|
|
61 | ev_ ## type ## _stop (w); \ |
|
|
62 | } while (0) |
|
|
63 | |
40 | typedef int Signal; |
64 | typedef int Signal; |
41 | |
65 | |
42 | static struct EVAPI evapi; |
66 | static struct EVAPI evapi; |
43 | |
67 | |
44 | static HV |
68 | static HV |
… | |
… | |
76 | } |
100 | } |
77 | |
101 | |
78 | ///////////////////////////////////////////////////////////////////////////// |
102 | ///////////////////////////////////////////////////////////////////////////// |
79 | // Event |
103 | // Event |
80 | |
104 | |
81 | static void e_cb (struct ev_watcher *w, int revents); |
105 | static void e_cb (ev_watcher *w, int revents); |
82 | |
106 | |
83 | static int |
107 | static int |
84 | sv_fileno (SV *fh) |
108 | sv_fileno (SV *fh) |
85 | { |
109 | { |
86 | SvGETMAGIC (fh); |
110 | SvGETMAGIC (fh); |
… | |
… | |
98 | } |
122 | } |
99 | |
123 | |
100 | static void * |
124 | static void * |
101 | e_new (int size, SV *cb_sv) |
125 | e_new (int size, SV *cb_sv) |
102 | { |
126 | { |
103 | struct ev_watcher *w; |
127 | ev_watcher *w; |
104 | SV *self = NEWSV (0, size); |
128 | SV *self = NEWSV (0, size); |
105 | SvPOK_only (self); |
129 | SvPOK_only (self); |
106 | SvCUR_set (self, size); |
130 | SvCUR_set (self, size); |
107 | |
131 | |
108 | w = (struct ev_watcher *)SvPVX (self); |
132 | w = (ev_watcher *)SvPVX (self); |
109 | |
133 | |
110 | ev_init (w, e_cb); |
134 | ev_init (w, e_cb); |
111 | |
135 | |
|
|
136 | w->flags = WFLAG_KEEPALIVE; |
112 | w->data = 0; |
137 | w->data = 0; |
113 | w->fh = 0; |
138 | w->fh = 0; |
114 | w->cb_sv = newSVsv (cb_sv); |
139 | w->cb_sv = newSVsv (cb_sv); |
115 | w->self = self; |
140 | w->self = self; |
116 | |
141 | |
… | |
… | |
118 | } |
143 | } |
119 | |
144 | |
120 | static void |
145 | static void |
121 | e_destroy (void *w_) |
146 | e_destroy (void *w_) |
122 | { |
147 | { |
123 | struct ev_watcher *w = (struct ev_watcher *)w_; |
148 | ev_watcher *w = (ev_watcher *)w_; |
124 | |
149 | |
125 | SvREFCNT_dec (w->fh ); w->fh = 0; |
150 | SvREFCNT_dec (w->fh ); w->fh = 0; |
126 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
151 | SvREFCNT_dec (w->cb_sv); w->cb_sv = 0; |
127 | SvREFCNT_dec (w->data ); w->data = 0; |
152 | SvREFCNT_dec (w->data ); w->data = 0; |
128 | } |
153 | } |
129 | |
154 | |
130 | static SV * |
155 | static SV * |
131 | e_bless (struct ev_watcher *w, HV *stash) |
156 | e_bless (ev_watcher *w, HV *stash) |
132 | { |
157 | { |
133 | SV *rv; |
158 | SV *rv; |
134 | |
159 | |
135 | if (SvOBJECT (w->self)) |
160 | if (SvOBJECT (w->self)) |
136 | rv = newRV_inc (w->self); |
161 | rv = newRV_inc (w->self); |
… | |
… | |
145 | } |
170 | } |
146 | |
171 | |
147 | static SV *sv_events_cache; |
172 | static SV *sv_events_cache; |
148 | |
173 | |
149 | static void |
174 | static void |
150 | e_cb (struct ev_watcher *w, int revents) |
175 | e_cb (ev_watcher *w, int revents) |
151 | { |
176 | { |
152 | dSP; |
177 | dSP; |
153 | I32 mark = SP - PL_stack_base; |
178 | I32 mark = SP - PL_stack_base; |
154 | SV *sv_self, *sv_events; |
179 | SV *sv_self, *sv_events; |
155 | |
180 | |
… | |
… | |
227 | SP = PL_stack_base + mark; |
252 | SP = PL_stack_base + mark; |
228 | PUTBACK; |
253 | PUTBACK; |
229 | } |
254 | } |
230 | |
255 | |
231 | static ev_tstamp |
256 | static ev_tstamp |
232 | e_periodic_cb (struct ev_periodic *w, ev_tstamp now) |
257 | e_periodic_cb (ev_periodic *w, ev_tstamp now) |
233 | { |
258 | { |
234 | ev_tstamp retval; |
259 | ev_tstamp retval; |
235 | int count; |
260 | int count; |
236 | dSP; |
261 | dSP; |
237 | |
262 | |
… | |
… | |
377 | |
402 | |
378 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
403 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
379 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
404 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
380 | |
405 | |
381 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
406 | stash_watcher = gv_stashpv ("EV::Watcher" , 1); |
382 | stash_io = gv_stashpv ("EV::Io" , 1); |
407 | stash_io = gv_stashpv ("EV::IO" , 1); |
383 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
408 | stash_timer = gv_stashpv ("EV::Timer" , 1); |
384 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
409 | stash_periodic = gv_stashpv ("EV::Periodic", 1); |
385 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
410 | stash_signal = gv_stashpv ("EV::Signal" , 1); |
386 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
411 | stash_idle = gv_stashpv ("EV::Idle" , 1); |
387 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
412 | stash_prepare = gv_stashpv ("EV::Prepare" , 1); |
… | |
… | |
418 | evapi.prepare_stop = ev_prepare_stop; |
443 | evapi.prepare_stop = ev_prepare_stop; |
419 | evapi.check_start = ev_check_start; |
444 | evapi.check_start = ev_check_start; |
420 | evapi.check_stop = ev_check_stop; |
445 | evapi.check_stop = ev_check_stop; |
421 | evapi.child_start = ev_child_start; |
446 | evapi.child_start = ev_child_start; |
422 | evapi.child_stop = ev_child_stop; |
447 | evapi.child_stop = ev_child_stop; |
|
|
448 | evapi.ref = ev_ref; |
|
|
449 | evapi.unref = ev_unref; |
423 | |
450 | |
424 | sv_setiv (sv, (IV)&evapi); |
451 | sv_setiv (sv, (IV)&evapi); |
425 | SvREADONLY_on (sv); |
452 | SvREADONLY_on (sv); |
426 | } |
453 | } |
427 | #ifndef _WIN32 |
454 | #ifndef _WIN32 |
… | |
… | |
439 | |
466 | |
440 | void ev_loop (int flags = 0) |
467 | void ev_loop (int flags = 0) |
441 | |
468 | |
442 | void ev_unloop (int how = 1) |
469 | void ev_unloop (int how = 1) |
443 | |
470 | |
444 | struct ev_io *io (SV *fh, int events, SV *cb) |
471 | ev_io *io (SV *fh, int events, SV *cb) |
445 | ALIAS: |
472 | ALIAS: |
446 | io_ns = 1 |
473 | io_ns = 1 |
447 | CODE: |
474 | CODE: |
448 | { |
475 | { |
449 | int fd = sv_fileno (fh); |
476 | int fd = sv_fileno (fh); |
450 | CHECK_FD (fh, fd); |
477 | CHECK_FD (fh, fd); |
451 | |
478 | |
452 | RETVAL = e_new (sizeof (struct ev_io), cb); |
479 | RETVAL = e_new (sizeof (ev_io), cb); |
453 | RETVAL->fh = newSVsv (fh); |
480 | RETVAL->fh = newSVsv (fh); |
454 | ev_io_set (RETVAL, fd, events); |
481 | ev_io_set (RETVAL, fd, events); |
455 | if (!ix) ev_io_start (RETVAL); |
482 | if (!ix) START (io, RETVAL); |
456 | } |
483 | } |
457 | OUTPUT: |
484 | OUTPUT: |
458 | RETVAL |
485 | RETVAL |
459 | |
486 | |
460 | struct ev_timer *timer (NV after, NV repeat, SV *cb) |
487 | ev_timer *timer (NV after, NV repeat, SV *cb) |
461 | ALIAS: |
488 | ALIAS: |
462 | timer_ns = 1 |
489 | timer_ns = 1 |
463 | INIT: |
490 | INIT: |
464 | CHECK_REPEAT (repeat); |
491 | CHECK_REPEAT (repeat); |
465 | CODE: |
492 | CODE: |
466 | RETVAL = e_new (sizeof (struct ev_timer), cb); |
493 | RETVAL = e_new (sizeof (ev_timer), cb); |
467 | ev_timer_set (RETVAL, after, repeat); |
494 | ev_timer_set (RETVAL, after, repeat); |
468 | if (!ix) ev_timer_start (RETVAL); |
495 | if (!ix) START (timer, RETVAL); |
469 | OUTPUT: |
496 | OUTPUT: |
470 | RETVAL |
497 | RETVAL |
471 | |
498 | |
472 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
499 | SV *periodic (NV at, NV interval, SV *reschedule_cb, SV *cb) |
473 | ALIAS: |
500 | ALIAS: |
474 | periodic_ns = 1 |
501 | periodic_ns = 1 |
475 | INIT: |
502 | INIT: |
476 | CHECK_REPEAT (interval); |
503 | CHECK_REPEAT (interval); |
477 | CODE: |
504 | CODE: |
478 | { |
505 | { |
479 | struct ev_periodic *w; |
506 | ev_periodic *w; |
480 | w = e_new (sizeof (struct ev_periodic), cb); |
507 | w = e_new (sizeof (ev_periodic), cb); |
481 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
508 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
482 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
509 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
483 | RETVAL = e_bless ((struct ev_watcher *)w, stash_periodic); |
510 | RETVAL = e_bless ((ev_watcher *)w, stash_periodic); |
484 | if (!ix) ev_periodic_start (w); |
511 | if (!ix) START (periodic, w); |
485 | } |
512 | } |
486 | OUTPUT: |
513 | OUTPUT: |
487 | RETVAL |
514 | RETVAL |
488 | |
515 | |
489 | struct ev_signal *signal (Signal signum, SV *cb) |
516 | ev_signal *signal (Signal signum, SV *cb) |
490 | ALIAS: |
517 | ALIAS: |
491 | signal_ns = 1 |
518 | signal_ns = 1 |
492 | CODE: |
519 | CODE: |
493 | RETVAL = e_new (sizeof (struct ev_signal), cb); |
520 | RETVAL = e_new (sizeof (ev_signal), cb); |
494 | ev_signal_set (RETVAL, signum); |
521 | ev_signal_set (RETVAL, signum); |
495 | if (!ix) ev_signal_start (RETVAL); |
522 | if (!ix) START (signal, RETVAL); |
496 | OUTPUT: |
523 | OUTPUT: |
497 | RETVAL |
524 | RETVAL |
498 | |
525 | |
499 | struct ev_idle *idle (SV *cb) |
526 | ev_idle *idle (SV *cb) |
500 | ALIAS: |
527 | ALIAS: |
501 | idle_ns = 1 |
528 | idle_ns = 1 |
502 | CODE: |
529 | CODE: |
503 | RETVAL = e_new (sizeof (struct ev_idle), cb); |
530 | RETVAL = e_new (sizeof (ev_idle), cb); |
504 | ev_idle_set (RETVAL); |
531 | ev_idle_set (RETVAL); |
505 | if (!ix) ev_idle_start (RETVAL); |
532 | if (!ix) START (idle, RETVAL); |
506 | OUTPUT: |
533 | OUTPUT: |
507 | RETVAL |
534 | RETVAL |
508 | |
535 | |
509 | struct ev_prepare *prepare (SV *cb) |
536 | ev_prepare *prepare (SV *cb) |
510 | ALIAS: |
537 | ALIAS: |
511 | prepare_ns = 1 |
538 | prepare_ns = 1 |
512 | CODE: |
539 | CODE: |
513 | RETVAL = e_new (sizeof (struct ev_prepare), cb); |
540 | RETVAL = e_new (sizeof (ev_prepare), cb); |
514 | ev_prepare_set (RETVAL); |
541 | ev_prepare_set (RETVAL); |
515 | if (!ix) ev_prepare_start (RETVAL); |
542 | if (!ix) START (prepare, RETVAL); |
516 | OUTPUT: |
543 | OUTPUT: |
517 | RETVAL |
544 | RETVAL |
518 | |
545 | |
519 | struct ev_check *check (SV *cb) |
546 | ev_check *check (SV *cb) |
520 | ALIAS: |
547 | ALIAS: |
521 | check_ns = 1 |
548 | check_ns = 1 |
522 | CODE: |
549 | CODE: |
523 | RETVAL = e_new (sizeof (struct ev_check), cb); |
550 | RETVAL = e_new (sizeof (ev_check), cb); |
524 | ev_check_set (RETVAL); |
551 | ev_check_set (RETVAL); |
525 | if (!ix) ev_check_start (RETVAL); |
552 | if (!ix) START (check, RETVAL); |
526 | OUTPUT: |
553 | OUTPUT: |
527 | RETVAL |
554 | RETVAL |
528 | |
555 | |
529 | struct ev_child *child (int pid, SV *cb) |
556 | ev_child *child (int pid, SV *cb) |
530 | ALIAS: |
557 | ALIAS: |
531 | child_ns = 1 |
558 | child_ns = 1 |
532 | CODE: |
559 | CODE: |
533 | RETVAL = e_new (sizeof (struct ev_child), cb); |
560 | RETVAL = e_new (sizeof (ev_child), cb); |
534 | ev_child_set (RETVAL, pid); |
561 | ev_child_set (RETVAL, pid); |
535 | if (!ix) ev_child_start (RETVAL); |
562 | if (!ix) START (child, RETVAL); |
536 | OUTPUT: |
563 | OUTPUT: |
537 | RETVAL |
564 | RETVAL |
538 | |
565 | |
539 | void once (SV *fh, int events, SV *timeout, SV *cb) |
566 | void once (SV *fh, int events, SV *timeout, SV *cb) |
540 | CODE: |
567 | CODE: |
… | |
… | |
547 | |
574 | |
548 | PROTOTYPES: DISABLE |
575 | PROTOTYPES: DISABLE |
549 | |
576 | |
550 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
577 | MODULE = EV PACKAGE = EV::Watcher PREFIX = ev_ |
551 | |
578 | |
552 | int ev_is_active (struct ev_watcher *w) |
579 | int ev_is_active (ev_watcher *w) |
553 | |
580 | |
|
|
581 | int ev_is_pending (ev_watcher *w) |
|
|
582 | |
|
|
583 | int keepalive (ev_watcher *w, int new_value = 0) |
|
|
584 | CODE: |
|
|
585 | { |
|
|
586 | RETVAL = w->flags & WFLAG_KEEPALIVE; |
|
|
587 | new_value = new_value ? WFLAG_KEEPALIVE : 0; |
|
|
588 | |
|
|
589 | if (items > 1 && ((new_value ^ w->flags) & WFLAG_KEEPALIVE)) |
|
|
590 | { |
|
|
591 | REF (w); |
|
|
592 | w->flags = (w->flags & ~WFLAG_KEEPALIVE) | new_value; |
|
|
593 | UNREF (w); |
|
|
594 | } |
|
|
595 | } |
|
|
596 | OUTPUT: |
|
|
597 | RETVAL |
|
|
598 | |
554 | SV *cb (struct ev_watcher *w, SV *new_cb = 0) |
599 | SV *cb (ev_watcher *w, SV *new_cb = 0) |
555 | CODE: |
600 | CODE: |
556 | { |
601 | { |
557 | RETVAL = newSVsv (w->cb_sv); |
602 | RETVAL = newSVsv (w->cb_sv); |
558 | |
603 | |
559 | if (items > 1) |
604 | if (items > 1) |
560 | sv_setsv (w->cb_sv, new_cb); |
605 | sv_setsv (w->cb_sv, new_cb); |
561 | } |
606 | } |
562 | OUTPUT: |
607 | OUTPUT: |
563 | RETVAL |
608 | RETVAL |
564 | |
609 | |
565 | SV *data (struct ev_watcher *w, SV *new_data = 0) |
610 | SV *data (ev_watcher *w, SV *new_data = 0) |
566 | CODE: |
611 | CODE: |
567 | { |
612 | { |
568 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
613 | RETVAL = w->data ? newSVsv (w->data) : &PL_sv_undef; |
569 | } |
|
|
570 | OUTPUT: |
|
|
571 | RETVAL |
|
|
572 | |
614 | |
|
|
615 | if (items > 1) |
|
|
616 | { |
|
|
617 | SvREFCNT_dec (w->data); |
|
|
618 | w->data = newSVsv (new_data); |
|
|
619 | } |
|
|
620 | } |
|
|
621 | OUTPUT: |
|
|
622 | RETVAL |
|
|
623 | |
573 | void trigger (struct ev_watcher *w, int revents = EV_NONE) |
624 | void trigger (ev_watcher *w, int revents = EV_NONE) |
574 | CODE: |
625 | CODE: |
575 | w->cb (w, revents); |
626 | w->cb (w, revents); |
576 | |
627 | |
577 | int priority (struct ev_watcher *w, int new_priority = 0) |
628 | int priority (ev_watcher *w, int new_priority = 0) |
578 | CODE: |
629 | CODE: |
579 | { |
630 | { |
580 | RETVAL = w->priority; |
631 | RETVAL = w->priority; |
581 | |
632 | |
582 | if (items > 1) |
633 | if (items > 1) |
… | |
… | |
605 | } |
656 | } |
606 | } |
657 | } |
607 | OUTPUT: |
658 | OUTPUT: |
608 | RETVAL |
659 | RETVAL |
609 | |
660 | |
610 | MODULE = EV PACKAGE = EV::Io PREFIX = ev_io_ |
661 | MODULE = EV PACKAGE = EV::IO PREFIX = ev_io_ |
611 | |
662 | |
612 | void ev_io_start (struct ev_io *w) |
663 | void ev_io_start (ev_io *w) |
|
|
664 | CODE: |
|
|
665 | START (io, w); |
613 | |
666 | |
614 | void ev_io_stop (struct ev_io *w) |
667 | void ev_io_stop (ev_io *w) |
|
|
668 | CODE: |
|
|
669 | STOP (io, w); |
615 | |
670 | |
616 | void DESTROY (struct ev_io *w) |
671 | void DESTROY (ev_io *w) |
617 | CODE: |
672 | CODE: |
618 | ev_io_stop (w); |
673 | STOP (io, w); |
619 | e_destroy (w); |
674 | e_destroy (w); |
620 | |
675 | |
621 | void set (struct ev_io *w, SV *fh, int events) |
676 | void set (ev_io *w, SV *fh, int events) |
622 | CODE: |
677 | CODE: |
623 | { |
678 | { |
624 | int active = ev_is_active (w); |
679 | int active = ev_is_active (w); |
625 | int fd = sv_fileno (fh); |
680 | int fd = sv_fileno (fh); |
626 | CHECK_FD (fh, fd); |
681 | CHECK_FD (fh, fd); |
627 | |
682 | |
628 | if (active) ev_io_stop (w); |
683 | if (active) STOP (io, w); |
629 | |
684 | |
630 | sv_setsv (w->fh, fh); |
685 | sv_setsv (w->fh, fh); |
631 | ev_io_set (w, fd, events); |
686 | ev_io_set (w, fd, events); |
632 | |
687 | |
633 | if (active) ev_io_start (w); |
688 | if (active) START (io, w); |
634 | } |
689 | } |
635 | |
690 | |
636 | SV *fh (struct ev_io *w, SV *new_fh = 0) |
691 | SV *fh (ev_io *w, SV *new_fh = 0) |
637 | CODE: |
692 | CODE: |
638 | { |
693 | { |
639 | RETVAL = newSVsv (w->fh); |
694 | RETVAL = newSVsv (w->fh); |
640 | |
695 | |
641 | if (items > 1) |
696 | if (items > 1) |
642 | { |
697 | { |
643 | int active = ev_is_active (w); |
698 | int active = ev_is_active (w); |
644 | if (active) ev_io_stop (w); |
699 | if (active) STOP (io, w); |
645 | |
700 | |
646 | sv_setsv (w->fh, new_fh); |
701 | sv_setsv (w->fh, new_fh); |
647 | ev_io_set (w, sv_fileno (w->fh), w->events); |
702 | ev_io_set (w, sv_fileno (w->fh), w->events); |
648 | |
703 | |
649 | if (active) ev_io_start (w); |
704 | if (active) START (io, w); |
650 | } |
705 | } |
651 | } |
706 | } |
652 | OUTPUT: |
707 | OUTPUT: |
653 | RETVAL |
708 | RETVAL |
654 | |
709 | |
655 | int events (struct ev_io *w, int new_events = EV_UNDEF) |
710 | int events (ev_io *w, int new_events = EV_UNDEF) |
656 | CODE: |
711 | CODE: |
657 | { |
712 | { |
658 | RETVAL = w->events; |
713 | RETVAL = w->events; |
659 | |
714 | |
660 | if (items > 1) |
715 | if (items > 1) |
661 | { |
716 | { |
662 | int active = ev_is_active (w); |
717 | int active = ev_is_active (w); |
663 | if (active) ev_io_stop (w); |
718 | if (active) STOP (io, w); |
664 | |
719 | |
665 | ev_io_set (w, w->fd, new_events); |
720 | ev_io_set (w, w->fd, new_events); |
666 | |
721 | |
667 | if (active) ev_io_start (w); |
722 | if (active) START (io, w); |
668 | } |
723 | } |
669 | } |
724 | } |
670 | OUTPUT: |
725 | OUTPUT: |
671 | RETVAL |
726 | RETVAL |
672 | |
727 | |
673 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
728 | MODULE = EV PACKAGE = EV::Signal PREFIX = ev_signal_ |
674 | |
729 | |
675 | void ev_signal_start (struct ev_signal *w) |
730 | void ev_signal_start (ev_signal *w) |
|
|
731 | CODE: |
|
|
732 | START (signal, w); |
676 | |
733 | |
677 | void ev_signal_stop (struct ev_signal *w) |
734 | void ev_signal_stop (ev_signal *w) |
|
|
735 | CODE: |
|
|
736 | STOP (signal, w); |
678 | |
737 | |
679 | void DESTROY (struct ev_signal *w) |
738 | void DESTROY (ev_signal *w) |
680 | CODE: |
739 | CODE: |
681 | ev_signal_stop (w); |
740 | STOP (signal, w); |
682 | e_destroy (w); |
741 | e_destroy (w); |
683 | |
742 | |
684 | void set (struct ev_signal *w, SV *signal) |
743 | void set (ev_signal *w, SV *signal) |
685 | CODE: |
744 | CODE: |
686 | { |
745 | { |
687 | Signal signum = sv_signum (signal); /* may croak here */ |
746 | Signal signum = sv_signum (signal); /* may croak here */ |
688 | int active = ev_is_active (w); |
747 | int active = ev_is_active (w); |
689 | |
748 | |
690 | if (active) ev_signal_stop (w); |
749 | if (active) STOP (signal, w); |
691 | |
750 | |
692 | ev_signal_set (w, signum); |
751 | ev_signal_set (w, signum); |
693 | |
752 | |
694 | if (active) ev_signal_start (w); |
753 | if (active) START (signal, w); |
695 | } |
754 | } |
696 | |
755 | |
697 | int signal (struct ev_signal *w, SV *new_signal = 0) |
756 | int signal (ev_signal *w, SV *new_signal = 0) |
698 | CODE: |
757 | CODE: |
699 | { |
758 | { |
700 | RETVAL = w->signum; |
759 | RETVAL = w->signum; |
701 | |
760 | |
702 | if (items > 1) |
761 | if (items > 1) |
703 | { |
762 | { |
704 | Signal signum = sv_signum (new_signal); /* may croak here */ |
763 | Signal signum = sv_signum (new_signal); /* may croak here */ |
705 | int active = ev_is_active (w); |
764 | int active = ev_is_active (w); |
706 | if (active) ev_signal_stop (w); |
765 | if (active) STOP (signal, w); |
707 | |
766 | |
708 | ev_signal_set (w, signum); |
767 | ev_signal_set (w, signum); |
709 | |
768 | |
710 | if (active) ev_signal_start (w); |
769 | if (active) START (signal, w); |
711 | } |
770 | } |
712 | } |
771 | } |
713 | OUTPUT: |
772 | OUTPUT: |
714 | RETVAL |
773 | RETVAL |
715 | |
774 | |
716 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
775 | MODULE = EV PACKAGE = EV::Timer PREFIX = ev_timer_ |
717 | |
776 | |
718 | void ev_timer_start (struct ev_timer *w) |
777 | void ev_timer_start (ev_timer *w) |
719 | INIT: |
778 | INIT: |
720 | CHECK_REPEAT (w->repeat); |
779 | CHECK_REPEAT (w->repeat); |
|
|
780 | CODE: |
|
|
781 | START (timer, w); |
721 | |
782 | |
722 | void ev_timer_stop (struct ev_timer *w) |
783 | void ev_timer_stop (ev_timer *w) |
|
|
784 | CODE: |
|
|
785 | STOP (timer, w); |
723 | |
786 | |
724 | void ev_timer_again (struct ev_timer *w) |
787 | void ev_timer_again (ev_timer *w) |
725 | INIT: |
788 | INIT: |
726 | CHECK_REPEAT (w->repeat); |
789 | CHECK_REPEAT (w->repeat); |
|
|
790 | CODE: |
|
|
791 | REF (w); |
|
|
792 | ev_timer_again (w); |
|
|
793 | UNREF (w); |
727 | |
794 | |
728 | void DESTROY (struct ev_timer *w) |
795 | void DESTROY (ev_timer *w) |
729 | CODE: |
796 | CODE: |
730 | ev_timer_stop (w); |
797 | STOP (timer, w); |
731 | e_destroy (w); |
798 | e_destroy (w); |
732 | |
799 | |
733 | void set (struct ev_timer *w, NV after, NV repeat = 0.) |
800 | void set (ev_timer *w, NV after, NV repeat = 0.) |
734 | INIT: |
801 | INIT: |
735 | CHECK_REPEAT (repeat); |
802 | CHECK_REPEAT (repeat); |
736 | CODE: |
803 | CODE: |
737 | { |
804 | { |
738 | int active = ev_is_active (w); |
805 | int active = ev_is_active (w); |
739 | if (active) ev_timer_stop (w); |
806 | if (active) STOP (timer, w); |
740 | ev_timer_set (w, after, repeat); |
807 | ev_timer_set (w, after, repeat); |
741 | if (active) ev_timer_start (w); |
808 | if (active) START (timer, w); |
742 | } |
809 | } |
743 | |
810 | |
744 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
811 | MODULE = EV PACKAGE = EV::Periodic PREFIX = ev_periodic_ |
745 | |
812 | |
746 | void ev_periodic_start (struct ev_periodic *w) |
813 | void ev_periodic_start (ev_periodic *w) |
747 | INIT: |
814 | INIT: |
748 | CHECK_REPEAT (w->interval); |
815 | CHECK_REPEAT (w->interval); |
|
|
816 | CODE: |
|
|
817 | START (periodic, w); |
749 | |
818 | |
750 | void ev_periodic_stop (struct ev_periodic *w) |
819 | void ev_periodic_stop (ev_periodic *w) |
|
|
820 | CODE: |
|
|
821 | STOP (periodic, w); |
751 | |
822 | |
752 | void ev_periodic_again (struct ev_periodic *w) |
823 | void ev_periodic_again (ev_periodic *w) |
|
|
824 | CODE: |
|
|
825 | REF (w); |
|
|
826 | ev_periodic_again (w); |
|
|
827 | UNREF (w); |
753 | |
828 | |
754 | void DESTROY (struct ev_periodic *w) |
829 | void DESTROY (ev_periodic *w) |
755 | CODE: |
830 | CODE: |
756 | ev_periodic_stop (w); |
831 | STOP (periodic, w); |
757 | e_destroy (w); |
832 | e_destroy (w); |
758 | |
833 | |
759 | void set (struct ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
834 | void set (ev_periodic *w, NV at, NV interval = 0., SV *reschedule_cb = &PL_sv_undef) |
760 | INIT: |
835 | INIT: |
761 | CHECK_REPEAT (interval); |
836 | CHECK_REPEAT (interval); |
762 | CODE: |
837 | CODE: |
763 | { |
838 | { |
764 | int active = ev_is_active (w); |
839 | int active = ev_is_active (w); |
765 | if (active) ev_periodic_stop (w); |
840 | if (active) STOP (periodic, w); |
766 | |
841 | |
767 | SvREFCNT_dec (w->fh); |
842 | SvREFCNT_dec (w->fh); |
768 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
843 | w->fh = SvTRUE (reschedule_cb) ? newSVsv (reschedule_cb) : 0; |
769 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
844 | ev_periodic_set (w, at, interval, w->fh ? e_periodic_cb : 0); |
770 | |
845 | |
771 | if (active) ev_periodic_start (w); |
846 | if (active) START (periodic, w); |
772 | } |
847 | } |
773 | |
848 | |
774 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
849 | MODULE = EV PACKAGE = EV::Idle PREFIX = ev_idle_ |
775 | |
850 | |
776 | void ev_idle_start (struct ev_idle *w) |
851 | void ev_idle_start (ev_idle *w) |
|
|
852 | CODE: |
|
|
853 | START (idle, w); |
777 | |
854 | |
778 | void ev_idle_stop (struct ev_idle *w) |
855 | void ev_idle_stop (ev_idle *w) |
|
|
856 | CODE: |
|
|
857 | STOP (idle, w); |
779 | |
858 | |
780 | void DESTROY (struct ev_idle *w) |
859 | void DESTROY (ev_idle *w) |
781 | CODE: |
860 | CODE: |
782 | ev_idle_stop (w); |
861 | STOP (idle, w); |
783 | e_destroy (w); |
862 | e_destroy (w); |
784 | |
863 | |
785 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
864 | MODULE = EV PACKAGE = EV::Prepare PREFIX = ev_check_ |
786 | |
865 | |
787 | void ev_prepare_start (struct ev_prepare *w) |
866 | void ev_prepare_start (ev_prepare *w) |
|
|
867 | CODE: |
|
|
868 | START (prepare, w); |
788 | |
869 | |
789 | void ev_prepare_stop (struct ev_prepare *w) |
870 | void ev_prepare_stop (ev_prepare *w) |
|
|
871 | CODE: |
|
|
872 | STOP (prepare, w); |
790 | |
873 | |
791 | void DESTROY (struct ev_prepare *w) |
874 | void DESTROY (ev_prepare *w) |
792 | CODE: |
875 | CODE: |
793 | ev_prepare_stop (w); |
876 | STOP (prepare, w); |
794 | e_destroy (w); |
877 | e_destroy (w); |
795 | |
878 | |
796 | MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ |
879 | MODULE = EV PACKAGE = EV::Check PREFIX = ev_check_ |
797 | |
880 | |
798 | void ev_check_start (struct ev_check *w) |
881 | void ev_check_start (ev_check *w) |
|
|
882 | CODE: |
|
|
883 | START (check, w); |
799 | |
884 | |
800 | void ev_check_stop (struct ev_check *w) |
885 | void ev_check_stop (ev_check *w) |
|
|
886 | CODE: |
|
|
887 | STOP (check, w); |
801 | |
888 | |
802 | void DESTROY (struct ev_check *w) |
889 | void DESTROY (ev_check *w) |
803 | CODE: |
890 | CODE: |
804 | ev_check_stop (w); |
891 | STOP (check, w); |
805 | e_destroy (w); |
892 | e_destroy (w); |
806 | |
893 | |
807 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
894 | MODULE = EV PACKAGE = EV::Child PREFIX = ev_child_ |
808 | |
895 | |
809 | void ev_child_start (struct ev_child *w) |
896 | void ev_child_start (ev_child *w) |
|
|
897 | CODE: |
|
|
898 | START (child, w); |
810 | |
899 | |
811 | void ev_child_stop (struct ev_child *w) |
900 | void ev_child_stop (ev_child *w) |
|
|
901 | CODE: |
|
|
902 | STOP (child, w); |
812 | |
903 | |
813 | void DESTROY (struct ev_child *w) |
904 | void DESTROY (ev_child *w) |
814 | CODE: |
905 | CODE: |
815 | ev_child_stop (w); |
906 | STOP (child, w); |
816 | e_destroy (w); |
907 | e_destroy (w); |
817 | |
908 | |
818 | void set (struct ev_child *w, int pid) |
909 | void set (ev_child *w, int pid) |
819 | CODE: |
910 | CODE: |
820 | { |
911 | { |
821 | int active = ev_is_active (w); |
912 | int active = ev_is_active (w); |
822 | if (active) ev_child_stop (w); |
913 | if (active) STOP (child, w); |
823 | |
914 | |
824 | ev_child_set (w, pid); |
915 | ev_child_set (w, pid); |
825 | |
916 | |
826 | if (active) ev_child_start (w); |
917 | if (active) START (child, w); |
827 | } |
918 | } |
828 | |
919 | |
829 | int pid (struct ev_child *w, int new_pid = 0) |
920 | int pid (ev_child *w, int new_pid = 0) |
830 | CODE: |
921 | CODE: |
831 | { |
922 | { |
832 | RETVAL = w->pid; |
923 | RETVAL = w->pid; |
833 | |
924 | |
834 | if (items > 1) |
925 | if (items > 1) |
835 | { |
926 | { |
836 | int active = ev_is_active (w); |
927 | int active = ev_is_active (w); |
837 | if (active) ev_child_stop (w); |
928 | if (active) STOP (child, w); |
838 | |
929 | |
839 | ev_child_set (w, new_pid); |
930 | ev_child_set (w, new_pid); |
840 | |
931 | |
841 | if (active) ev_child_start (w); |
932 | if (active) START (child, w); |
842 | } |
933 | } |
843 | } |
934 | } |
844 | OUTPUT: |
935 | OUTPUT: |
845 | RETVAL |
936 | RETVAL |
846 | |
937 | |
847 | |
938 | |
848 | int rstatus (struct ev_child *w) |
939 | int rstatus (ev_child *w) |
849 | ALIAS: |
940 | ALIAS: |
850 | rpid = 1 |
941 | rpid = 1 |
851 | CODE: |
942 | CODE: |
852 | RETVAL = ix ? w->rpid : w->rstatus; |
943 | RETVAL = ix ? w->rpid : w->rstatus; |
853 | OUTPUT: |
944 | OUTPUT: |