ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/EV.pm
(Generate patch)

Comparing EV/EV.pm (file contents):
Revision 1.78 by root, Sat Dec 22 11:50:04 2007 UTC vs.
Revision 1.88 by root, Wed Apr 16 17:08:29 2008 UTC

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
68package EV; 68package EV;
69 69
70use strict; 70use strict;
71 71
72BEGIN { 72BEGIN {
73 our $VERSION = '2.0'; 73 our $VERSION = '3.3';
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
102selecting a working backend (which for example rules out kqueue on most 103selecting a working backend (which for example rules out kqueue on most
103BSDs). Modules should, unless they have "special needs" always use the 104BSDs). Modules should, unless they have "special needs" always use the
104default loop as this is fastest (perl-wise), best supported by other 105default loop as this is fastest (perl-wise), best supported by other
105modules (e.g. AnyEvent or Coro) and most portable event loop. 106modules (e.g. AnyEvent or Coro) and most portable event loop.
106 107
107For specific programs you cna create additional event loops dynamically. 108For 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
126Must be called after a fork in the child, before entering or continuing 127Must be called after a fork in the child, before entering or continuing
127the event loop. An alternative is to use C<EV::FLAG_FORKCHECK> which calls 128the event loop. An alternative is to use C<EV::FLAG_FORKCHECK> which calls
128this fucntion automatically, at some performance loss (refer to the libev 129this fucntion automatically, at some performance loss (refer to the libev
129documentation). 130documentation).
130 131
132=item $loop = EV::default_loop [$flags]
133
134Return 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
140Must contain a reference to a function that is called when a callback 145Must contain a reference to a function that is called when a callback
141throws an exception (with $@ containing the error). The default prints an 146throws an exception (with $@ containing the error). The default prints an
142informative message and continues. 147informative message and continues.
143 148
144If this callback throws an exception it will be silently ignored. 149If 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
157Returns the set (see C<EV::BACKEND_*> flags) of backends supported by this
158instance of EV, the set of recommended backends (supposed to be good) for
159this platform and the set of embeddable backends (see EMBED WATCHERS).
160
161=item EV::sleep $seconds
162
163Block the process for the given number of (fractional) seconds.
145 164
146=item $time = EV::time 165=item $time = EV::time
147 166
148Returns the current time in (fractional) seconds since the epoch. 167Returns 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
230Feed a signal event into EV. EV will react to this call as if the signal 249Feed a signal event into EV. EV will react to this call as if the signal
231specified by C<$signal> had occured. 250specified 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
260These advanced functions set the minimum block interval when polling for I/O events and the minimum
261wait interval for timer events. See the libev documentation at
262L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#FUNCTIONS_CONTROLLING_THE_EVENT_LOOP> for
263a more detailed discussion.
232 264
233=back 265=back
234 266
235 267
236=head1 WATCHER OBJECTS 268=head1 WATCHER OBJECTS
502This time simply fires at the wallclock time C<$at> and doesn't repeat. It 534This time simply fires at the wallclock time C<$at> and doesn't repeat. It
503will not adjust when a time jump occurs, that is, if it is to be run 535will not adjust when a time jump occurs, that is, if it is to be run
504at January 1st 2011 then it will run when the system time reaches or 536at January 1st 2011 then it will run when the system time reaches or
505surpasses this time. 537surpasses 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
509In this mode the watcher will always be scheduled to time out at the 541In this mode the watcher will always be scheduled to time out at the
510next C<$at + N * $interval> time (for some integer N) and then repeat, 542next C<$at + N * $interval> time (for some integer N) and then repeat,
511regardless of any time jumps. 543regardless 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
626Call the callback when a status change for pid C<$pid> (or any pid if 658Call the callback when a status change for pid C<$pid> (or any pid
627C<$pid> is 0) has been received. More precisely: when the process receives 659if C<$pid> is 0) has been received (a status change happens when the
660process terminates or is killed, or, when trace is true, additionally when
661it is stopped or continued). More precisely: when the process receives
628a C<SIGCHLD>, EV will fetch the outstanding exit/wait status for all 662a C<SIGCHLD>, EV will fetch the outstanding exit/wait status for all
629changed/zombie children and call the callback. 663changed/zombie children and call the callback.
630 664
631It is valid (and fully supported) to install a child watcher after a child 665It is valid (and fully supported) to install a child watcher after a child
632has exited but before the event loop has started its next iteration (for 666has exited but before the event loop has started its next iteration (for
639You can have as many pid watchers per pid as you want, they will all be 673You can have as many pid watchers per pid as you want, they will all be
640called. 674called.
641 675
642The C<child_ns> variant doesn't start (activate) the newly created watcher. 676The 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
646Reconfigures the watcher, see the constructor above for details. Can be called at 680Reconfigures the watcher, see the constructor above for details. Can be called at
647any time. 681any 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
653Returns the previously set process id and optionally set a new one. 685Returns 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
887Call the callback before the event loop is resumed in the child process 919Call the callback before the event loop is resumed in the child process
888after a fork. 920after a fork.
889 921
890The C<fork_ns> variant doesn't start (activate) the newly created watcher. 922The 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
929This is a rather advanced watcher type that lets you embed one event loop
930into another (currently only IO events are supported in the embedded
931loop, other types of watchers might be handled in a delayed or incorrect
932fashion and must not be used).
933
934See the libev documentation at
935L<http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_embed_code_when_one_backend_>
936for more details.
937
938In short, this watcher is most useful on BSD systems without working
939kqueue 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
965Call the callback when the embedded event loop (C<$otherloop>) has any
966I/O activity. The C<$callback> should alwas be specified as C<undef> in
967this version of EV, which means the embedded event loop will be managed
968automatically.
969
970The 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
976Async watchers are provided by EV, but have little use in perl directly, as perl
977neither supports threads nor direct access to signal handlers or other
978contexts where they could be of value.
979
980It is, however, possible to use them from the XS level.
981
982Please 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines