… | |
… | |
35 | warn "sigquit received\n"; |
35 | warn "sigquit received\n"; |
36 | }; |
36 | }; |
37 | |
37 | |
38 | # CHILD/PID STATUS CHANGES |
38 | # CHILD/PID STATUS CHANGES |
39 | |
39 | |
40 | my $w = EV::child 666, sub { |
40 | my $w = EV::child 666, 0, sub { |
41 | my ($w, $revents) = @_; |
41 | my ($w, $revents) = @_; |
42 | my $status = $w->rstatus; |
42 | my $status = $w->rstatus; |
43 | }; |
43 | }; |
44 | |
44 | |
45 | # STAT CHANGES |
45 | # STAT CHANGES |
… | |
… | |
68 | package EV; |
68 | package EV; |
69 | |
69 | |
70 | use strict; |
70 | use strict; |
71 | |
71 | |
72 | BEGIN { |
72 | BEGIN { |
73 | our $VERSION = '2.0'; |
73 | our $VERSION = '3.2'; |
74 | use XSLoader; |
74 | use XSLoader; |
75 | XSLoader::load "EV", $VERSION; |
75 | XSLoader::load "EV", $VERSION; |
76 | } |
76 | } |
77 | |
77 | |
78 | @EV::IO::ISA = |
78 | @EV::IO::ISA = |
… | |
… | |
84 | @EV::Idle::ISA = |
84 | @EV::Idle::ISA = |
85 | @EV::Prepare::ISA = |
85 | @EV::Prepare::ISA = |
86 | @EV::Check::ISA = |
86 | @EV::Check::ISA = |
87 | @EV::Embed::ISA = |
87 | @EV::Embed::ISA = |
88 | @EV::Fork::ISA = |
88 | @EV::Fork::ISA = |
|
|
89 | @EV::Async::ISA = |
89 | "EV::Watcher"; |
90 | "EV::Watcher"; |
90 | |
91 | |
91 | @EV::Loop::Default::ISA = "EV::Loop"; |
92 | @EV::Loop::Default::ISA = "EV::Loop"; |
92 | |
93 | |
93 | =head1 EVENT LOOPS |
94 | =head1 EVENT LOOPS |
… | |
… | |
102 | selecting a working backend (which for example rules out kqueue on most |
103 | selecting a working backend (which for example rules out kqueue on most |
103 | BSDs). Modules should, unless they have "special needs" always use the |
104 | BSDs). Modules should, unless they have "special needs" always use the |
104 | default loop as this is fastest (perl-wise), best supported by other |
105 | default loop as this is fastest (perl-wise), best supported by other |
105 | modules (e.g. AnyEvent or Coro) and most portable event loop. |
106 | modules (e.g. AnyEvent or Coro) and most portable event loop. |
106 | |
107 | |
107 | For specific programs you cna create additional event loops dynamically. |
108 | For specific programs you can create additional event loops dynamically. |
108 | |
109 | |
109 | =over 4 |
110 | =over 4 |
110 | |
111 | |
111 | =item $loop = new EV::loop [$flags] |
112 | =item $loop = new EV::loop [$flags] |
112 | |
113 | |
… | |
… | |
126 | Must be called after a fork in the child, before entering or continuing |
127 | Must be called after a fork in the child, before entering or continuing |
127 | the event loop. An alternative is to use C<EV::FLAG_FORKCHECK> which calls |
128 | the event loop. An alternative is to use C<EV::FLAG_FORKCHECK> which calls |
128 | this fucntion automatically, at some performance loss (refer to the libev |
129 | this fucntion automatically, at some performance loss (refer to the libev |
129 | documentation). |
130 | documentation). |
130 | |
131 | |
|
|
132 | =item $loop = EV::default_loop [$flags] |
|
|
133 | |
|
|
134 | Return the default loop (which is a singleton object). |
|
|
135 | |
131 | =back |
136 | =back |
132 | |
137 | |
133 | |
138 | |
134 | =head1 BASIC INTERFACE |
139 | =head1 BASIC INTERFACE |
135 | |
140 | |
… | |
… | |
140 | Must contain a reference to a function that is called when a callback |
145 | Must contain a reference to a function that is called when a callback |
141 | throws an exception (with $@ containing the error). The default prints an |
146 | throws an exception (with $@ containing the error). The default prints an |
142 | informative message and continues. |
147 | informative message and continues. |
143 | |
148 | |
144 | If this callback throws an exception it will be silently ignored. |
149 | If this callback throws an exception it will be silently ignored. |
|
|
150 | |
|
|
151 | =item $flags = EV::supported_backends |
|
|
152 | |
|
|
153 | =item $flags = EV::recommended_backends |
|
|
154 | |
|
|
155 | =item $flags = EV::embeddable_backends |
|
|
156 | |
|
|
157 | Returns the set (see C<EV::BACKEND_*> flags) of backends supported by this |
|
|
158 | instance of EV, the set of recommended backends (supposed to be good) for |
|
|
159 | this platform and the set of embeddable backends (see EMBED WATCHERS). |
|
|
160 | |
|
|
161 | =item EV::sleep $seconds |
|
|
162 | |
|
|
163 | Block the process for the given number of (fractional) seconds. |
145 | |
164 | |
146 | =item $time = EV::time |
165 | =item $time = EV::time |
147 | |
166 | |
148 | Returns the current time in (fractional) seconds since the epoch. |
167 | Returns the current time in (fractional) seconds since the epoch. |
149 | |
168 | |
… | |
… | |
227 | |
246 | |
228 | =item EV::feed_signal_event ($signal) |
247 | =item EV::feed_signal_event ($signal) |
229 | |
248 | |
230 | Feed a signal event into EV. EV will react to this call as if the signal |
249 | Feed a signal event into EV. EV will react to this call as if the signal |
231 | specified by C<$signal> had occured. |
250 | specified by C<$signal> had occured. |
|
|
251 | |
|
|
252 | =item EV::set_io_collect_interval $time |
|
|
253 | |
|
|
254 | =item $loop->set_io_collect_interval ($time) |
|
|
255 | |
|
|
256 | =item EV::set_timeout_collect_interval $time |
|
|
257 | |
|
|
258 | =item $loop->set_timeout_collect_interval ($time) |
|
|
259 | |
|
|
260 | These advanced functions set the minimum block interval when polling for I/O events and the minimum |
|
|
261 | wait interval for timer events. See the libev documentation at |
|
|
262 | L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONTROLLING_THE_EVENT_LOOP> for |
|
|
263 | a more detailed discussion. |
232 | |
264 | |
233 | =back |
265 | =back |
234 | |
266 | |
235 | |
267 | |
236 | =head1 WATCHER OBJECTS |
268 | =head1 WATCHER OBJECTS |
… | |
… | |
333 | Feed some events on this watcher into EV. EV will react to this call as if |
365 | Feed some events on this watcher into EV. EV will react to this call as if |
334 | the watcher had received the given C<$revents> mask. |
366 | the watcher had received the given C<$revents> mask. |
335 | |
367 | |
336 | =item $revents = $w->clear_pending |
368 | =item $revents = $w->clear_pending |
337 | |
369 | |
338 | If the watcher is pending, this function returns clears its pending status |
370 | If the watcher is pending, this function clears its pending status and |
339 | and returns its C<$revents> bitset (as if its callback was invoked). If the |
371 | returns its C<$revents> bitset (as if its callback was invoked). If the |
340 | watcher isn't pending it does nothing and returns C<0>. |
372 | watcher isn't pending it does nothing and returns C<0>. |
341 | |
373 | |
342 | =item $previous_state = $w->keepalive ($bool) |
374 | =item $previous_state = $w->keepalive ($bool) |
343 | |
375 | |
344 | Normally, C<EV::loop> will return when there are no active watchers |
376 | Normally, C<EV::loop> will return when there are no active watchers |
… | |
… | |
502 | This time simply fires at the wallclock time C<$at> and doesn't repeat. It |
534 | This time simply fires at the wallclock time C<$at> and doesn't repeat. It |
503 | will not adjust when a time jump occurs, that is, if it is to be run |
535 | will not adjust when a time jump occurs, that is, if it is to be run |
504 | at January 1st 2011 then it will run when the system time reaches or |
536 | at January 1st 2011 then it will run when the system time reaches or |
505 | surpasses this time. |
537 | surpasses this time. |
506 | |
538 | |
507 | =item * non-repeating interval timer ($interval > 0, $reschedule_cb = 0) |
539 | =item * repeating interval timer ($interval > 0, $reschedule_cb = 0) |
508 | |
540 | |
509 | In this mode the watcher will always be scheduled to time out at the |
541 | In this mode the watcher will always be scheduled to time out at the |
510 | next C<$at + N * $interval> time (for some integer N) and then repeat, |
542 | next C<$at + N * $interval> time (for some integer N) and then repeat, |
511 | regardless of any time jumps. |
543 | regardless of any time jumps. |
512 | |
544 | |
… | |
… | |
613 | |
645 | |
614 | =head3 CHILD WATCHERS - watch out for process status changes |
646 | =head3 CHILD WATCHERS - watch out for process status changes |
615 | |
647 | |
616 | =over 4 |
648 | =over 4 |
617 | |
649 | |
618 | =item $w = EV::child $pid, $callback |
650 | =item $w = EV::child $pid, $trace, $callback |
619 | |
651 | |
620 | =item $w = EV::child_ns $pid, $callback |
652 | =item $w = EV::child_ns $pid, $trace, $callback |
621 | |
653 | |
622 | =item $w = $loop->child ($pid, $callback) |
654 | =item $w = $loop->child ($pid, $trace, $callback) |
623 | |
655 | |
624 | =item $w = $loop->child_ns ($pid, $callback) |
656 | =item $w = $loop->child_ns ($pid, $trace, $callback) |
625 | |
657 | |
626 | Call the callback when a status change for pid C<$pid> (or any pid if |
658 | Call the callback when a status change for pid C<$pid> (or any pid |
627 | C<$pid> is 0) has been received. More precisely: when the process receives |
659 | if C<$pid> is 0) has been received (a status change happens when the |
|
|
660 | process terminates or is killed, or, when trace is true, additionally when |
|
|
661 | it is stopped or continued). More precisely: when the process receives |
628 | a C<SIGCHLD>, EV will fetch the outstanding exit/wait status for all |
662 | a C<SIGCHLD>, EV will fetch the outstanding exit/wait status for all |
629 | changed/zombie children and call the callback. |
663 | changed/zombie children and call the callback. |
630 | |
664 | |
631 | It is valid (and fully supported) to install a child watcher after a child |
665 | It is valid (and fully supported) to install a child watcher after a child |
632 | has exited but before the event loop has started its next iteration (for |
666 | has exited but before the event loop has started its next iteration (for |
… | |
… | |
639 | You can have as many pid watchers per pid as you want, they will all be |
673 | You can have as many pid watchers per pid as you want, they will all be |
640 | called. |
674 | called. |
641 | |
675 | |
642 | The C<child_ns> variant doesn't start (activate) the newly created watcher. |
676 | The C<child_ns> variant doesn't start (activate) the newly created watcher. |
643 | |
677 | |
644 | =item $w->set ($pid) |
678 | =item $w->set ($pid, $trace) |
645 | |
679 | |
646 | Reconfigures the watcher, see the constructor above for details. Can be called at |
680 | Reconfigures the watcher, see the constructor above for details. Can be called at |
647 | any time. |
681 | any time. |
648 | |
682 | |
649 | =item $current_pid = $w->pid |
683 | =item $current_pid = $w->pid |
650 | |
|
|
651 | =item $old_pid = $w->pid ($new_pid) |
|
|
652 | |
684 | |
653 | Returns the previously set process id and optionally set a new one. |
685 | Returns the previously set process id and optionally set a new one. |
654 | |
686 | |
655 | =item $exit_status = $w->rstatus |
687 | =item $exit_status = $w->rstatus |
656 | |
688 | |
… | |
… | |
886 | |
918 | |
887 | Call the callback before the event loop is resumed in the child process |
919 | Call the callback before the event loop is resumed in the child process |
888 | after a fork. |
920 | after a fork. |
889 | |
921 | |
890 | The C<fork_ns> variant doesn't start (activate) the newly created watcher. |
922 | The C<fork_ns> variant doesn't start (activate) the newly created watcher. |
|
|
923 | |
|
|
924 | =back |
|
|
925 | |
|
|
926 | |
|
|
927 | =head3 EMBED WATCHERS - when one backend isn't enough... |
|
|
928 | |
|
|
929 | This is a rather advanced watcher type that lets you embed one event loop |
|
|
930 | into another (currently only IO events are supported in the embedded |
|
|
931 | loop, other types of watchers might be handled in a delayed or incorrect |
|
|
932 | fashion and must not be used). |
|
|
933 | |
|
|
934 | See the libev documentation at |
|
|
935 | L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code_when_one_backend_> |
|
|
936 | for more details. |
|
|
937 | |
|
|
938 | In short, this watcher is most useful on BSD systems without working |
|
|
939 | kqueue to still be able to handle a large number of sockets: |
|
|
940 | |
|
|
941 | my $socket_loop; |
|
|
942 | |
|
|
943 | # check wether we use SELECT or POLL _and_ KQUEUE is supported |
|
|
944 | if ( |
|
|
945 | (EV::backend & (EV::BACKEND_POLL | EV::BACKEND_SELECT)) |
|
|
946 | && (EV::supported_backends & EV::embeddable_backends & EV::BACKEND_KQUEUE) |
|
|
947 | ) { |
|
|
948 | # use kqueue for sockets |
|
|
949 | $socket_loop = new EV::Loop EV::BACKEND_KQUEUE | EV::FLAG_NOENV; |
|
|
950 | } |
|
|
951 | |
|
|
952 | # use the default loop otherwise |
|
|
953 | $socket_loop ||= EV::default_loop; |
|
|
954 | |
|
|
955 | =over 4 |
|
|
956 | |
|
|
957 | =item $w = EV::embed $otherloop, $callback |
|
|
958 | |
|
|
959 | =item $w = EV::embed_ns $otherloop, $callback |
|
|
960 | |
|
|
961 | =item $w = $loop->embed ($otherloop, $callback) |
|
|
962 | |
|
|
963 | =item $w = $loop->embed_ns ($otherloop, $callback) |
|
|
964 | |
|
|
965 | Call the callback when the embedded event loop (C<$otherloop>) has any |
|
|
966 | I/O activity. The C<$callback> should alwas be specified as C<undef> in |
|
|
967 | this version of EV, which means the embedded event loop will be managed |
|
|
968 | automatically. |
|
|
969 | |
|
|
970 | The C<embed_ns> variant doesn't start (activate) the newly created watcher. |
|
|
971 | |
|
|
972 | =back |
|
|
973 | |
|
|
974 | =head3 ASYNC WATCHERS - how to wake up another event loop |
|
|
975 | |
|
|
976 | Async watchers are provided by EV, but have little use in perl directly, as perl |
|
|
977 | neither supports threads nor direct access to signal handlers or other |
|
|
978 | contexts where they could be of value. |
|
|
979 | |
|
|
980 | It is, however, possible to use them from the XS level. |
|
|
981 | |
|
|
982 | Please see the libev documentation for further details. |
|
|
983 | |
|
|
984 | =over 4 |
|
|
985 | |
|
|
986 | =item $w = EV::async $callback |
|
|
987 | |
|
|
988 | =item $w = EV::async_ns $callback |
|
|
989 | |
|
|
990 | =item $w->send |
|
|
991 | |
|
|
992 | =item $bool = $w->async_pending |
891 | |
993 | |
892 | =back |
994 | =back |
893 | |
995 | |
894 | |
996 | |
895 | =head1 PERL SIGNALS |
997 | =head1 PERL SIGNALS |