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

Comparing EV/EV.pm (file contents):
Revision 1.73 by root, Fri Dec 21 05:10:01 2007 UTC vs.
Revision 1.77 by root, Sat Dec 22 11:44:50 2007 UTC

208If timeout is C<undef> or negative, then there will be no 208If timeout is C<undef> or negative, then there will be no
209timeout. Otherwise a EV::timer with this value will be started. 209timeout. Otherwise a EV::timer with this value will be started.
210 210
211When an error occurs or either the timeout or I/O watcher triggers, then 211When an error occurs or either the timeout or I/O watcher triggers, then
212the callback will be called with the received event set (in general 212the callback will be called with the received event set (in general
213you can expect it to be a combination of C<EV:ERROR>, C<EV::READ>, 213you can expect it to be a combination of C<EV::ERROR>, C<EV::READ>,
214C<EV::WRITE> and C<EV::TIMEOUT>). 214C<EV::WRITE> and C<EV::TIMEOUT>).
215 215
216EV::once doesn't return anything: the watchers stay active till either 216EV::once doesn't return anything: the watchers stay active till either
217of them triggers, then they will be stopped and freed, and the callback 217of them triggers, then they will be stopped and freed, and the callback
218invoked. 218invoked.
239event. For instance, if you want to wait for STDIN to become readable, you 239event. For instance, if you want to wait for STDIN to become readable, you
240would create an EV::io watcher for that: 240would create an EV::io watcher for that:
241 241
242 my $watcher = EV::io *STDIN, EV::READ, sub { 242 my $watcher = EV::io *STDIN, EV::READ, sub {
243 my ($watcher, $revents) = @_; 243 my ($watcher, $revents) = @_;
244 warn "yeah, STDIN should not be readable without blocking!\n" 244 warn "yeah, STDIN should now be readable without blocking!\n"
245 }; 245 };
246 246
247All watchers can be active (waiting for events) or inactive (paused). Only 247All watchers can be active (waiting for events) or inactive (paused). Only
248active watchers will have their callbacks invoked. All callbacks will be 248active watchers will have their callbacks invoked. All callbacks will be
249called with at least two arguments: the watcher and a bitmask of received 249called with at least two arguments: the watcher and a bitmask of received
345(which is a "deadlock" because no progress can be made anymore). This is 345(which is a "deadlock" because no progress can be made anymore). This is
346convinient because it allows you to start your watchers (and your jobs), 346convinient because it allows you to start your watchers (and your jobs),
347call C<EV::loop> once and when it returns you know that all your jobs are 347call C<EV::loop> once and when it returns you know that all your jobs are
348finished (or they forgot to register some watchers for their task :). 348finished (or they forgot to register some watchers for their task :).
349 349
350Sometimes, however, this gets in your way, for example when you the module 350Sometimes, however, this gets in your way, for example when the module
351that calls C<EV::loop> (usually the main program) is not the same module 351that calls C<EV::loop> (usually the main program) is not the same module
352as a long-living watcher (for example a DNS client module written by 352as a long-living watcher (for example a DNS client module written by
353somebody else even). Then you might want any outstanding requests to be 353somebody else even). Then you might want any outstanding requests to be
354handled, but you would not want to keep C<EV::loop> from returning just 354handled, but you would not want to keep C<EV::loop> from returning just
355because you happen to have this long-running UDP port watcher. 355because you happen to have this long-running UDP port watcher.
363Example: Register an I/O watcher for some UDP socket but do not keep the 363Example: Register an I/O watcher for some UDP socket but do not keep the
364event loop from running just because of that watcher. 364event loop from running just because of that watcher.
365 365
366 my $udp_socket = ... 366 my $udp_socket = ...
367 my $udp_watcher = EV::io $udp_socket, EV::READ, sub { ... }; 367 my $udp_watcher = EV::io $udp_socket, EV::READ, sub { ... };
368 $udp_watcher->keepalive (0); 368 $1000udp_watcher->keepalive (0);
369
370=item $loop = $w->loop
371
372Return the loop that this watcher is attached to.
369 373
370=back 374=back
371 375
372 376
373=head1 WATCHER TYPES 377=head1 WATCHER TYPES
380 384
381=item $w = EV::io $fileno_or_fh, $eventmask, $callback 385=item $w = EV::io $fileno_or_fh, $eventmask, $callback
382 386
383=item $w = EV::io_ns $fileno_or_fh, $eventmask, $callback 387=item $w = EV::io_ns $fileno_or_fh, $eventmask, $callback
384 388
385=item $w = $loop->io 8$fileno_or_fh, $eventmask, $callback) 389=item $w = $loop->io ($fileno_or_fh, $eventmask, $callback)
386 390
387=item $w = $loop->io_ns ($fileno_or_fh, $eventmask, $callback) 391=item $w = $loop->io_ns ($fileno_or_fh, $eventmask, $callback)
388 392
389As long as the returned watcher object is alive, call the C<$callback> 393As long as the returned watcher object is alive, call the C<$callback>
390when at least one of events specified in C<$eventmask> occurs. 394when at least one of events specified in C<$eventmask> occurs.
787 791
788=item $w = EV::prepare_ns $callback 792=item $w = EV::prepare_ns $callback
789 793
790=item $w = $loop->prepare ($callback) 794=item $w = $loop->prepare ($callback)
791 795
792=item $w = $loop->prepare_ns 8$callback) 796=item $w = $loop->prepare_ns ($callback)
793 797
794Call the callback just before the process would block. You can still 798Call the callback just before the process would block. You can still
795create/modify any watchers at this point. 799create/modify any watchers at this point.
796 800
797See the EV::check watcher, below, for explanations and an example. 801See the EV::check watcher, below, for explanations and an example.
902to be called on every event loop iteration by installing a C<EV::check> 906to be called on every event loop iteration by installing a C<EV::check>
903watcher: 907watcher:
904 908
905 my $async_check = EV::check sub { }; 909 my $async_check = EV::check sub { };
906 910
907This ensures that perl shortly gets into control for a short time, and 911This ensures that perl gets into control for a short time to handle any
908also ensures slower overall operation. 912pending signals, and also ensures (slightly) slower overall operation.
909 913
910=head1 THREADS 914=head1 THREADS
911 915
912Threads are not supported by this module in any way. Perl pseudo-threads 916Threads are not supported by this module in any way. Perl pseudo-threads
913is evil stuff and must die. As soon as Perl gains real threads I will work 917is evil stuff and must die. As soon as Perl gains real threads I will work

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines