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

Comparing EV/README (file contents):
Revision 1.13 by root, Tue Nov 27 16:35:47 2007 UTC vs.
Revision 1.16 by root, Fri Dec 7 18:11:23 2007 UTC

56 This module provides an interface to libev 56 This module provides an interface to libev
57 (<http://software.schmorp.de/pkg/libev.html>). While the documentation 57 (<http://software.schmorp.de/pkg/libev.html>). While the documentation
58 below is comprehensive, one might also consult the documentation of 58 below is comprehensive, one might also consult the documentation of
59 libev itself (<http://cvs.schmorp.de/libev/ev.html>) for more subtle 59 libev itself (<http://cvs.schmorp.de/libev/ev.html>) for more subtle
60 details on watcher semantics or some discussion on the available 60 details on watcher semantics or some discussion on the available
61 backends, or how to force a specific backend with "LIBEV_FLAGS". 61 backends, or how to force a specific backend with "LIBEV_FLAGS", or just
62 about in any case because it has much more detailed information.
62 63
63BASIC INTERFACE 64BASIC INTERFACE
64 $EV::DIED 65 $EV::DIED
65 Must contain a reference to a function that is called when a 66 Must contain a reference to a function that is called when a
66 callback throws an exception (with $@ containing thr error). The 67 callback throws an exception (with $@ containing thr error). The
95 makes the innermost call to EV::loop return. 96 makes the innermost call to EV::loop return.
96 97
97 When called with an argument of EV::UNLOOP_ALL, all calls to 98 When called with an argument of EV::UNLOOP_ALL, all calls to
98 EV::loop will return as fast as possible. 99 EV::loop will return as fast as possible.
99 100
101 $count = EV::loop_count
102 Return the number of times the event loop has polled for new events.
103 Sometiems useful as a generation counter.
104
100 EV::once $fh_or_undef, $events, $timeout, $cb->($revents) 105 EV::once $fh_or_undef, $events, $timeout, $cb->($revents)
101 This function rolls together an I/O and a timer watcher for a single 106 This function rolls together an I/O and a timer watcher for a single
102 one-shot event without the need for managing a watcher object. 107 one-shot event without the need for managing a watcher object.
103 108
104 If $fh_or_undef is a filehandle or file descriptor, then $events 109 If $fh_or_undef is a filehandle or file descriptor, then $events
135 received events. 140 received events.
136 141
137 Each watcher type has its associated bit in revents, so you can use the 142 Each watcher type has its associated bit in revents, so you can use the
138 same callback for multiple watchers. The event mask is named after the 143 same callback for multiple watchers. The event mask is named after the
139 type, i..e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, 144 type, i..e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE,
140 EV::periodic sets EV::PERIODIC and so on, with the exception of IO 145 EV::periodic sets EV::PERIODIC and so on, with the exception of I/O
141 events (which can set both EV::READ and EV::WRITE bits), and EV::timer 146 events (which can set both EV::READ and EV::WRITE bits), and EV::timer
142 (which uses EV::TIMEOUT). 147 (which uses EV::TIMEOUT).
143 148
144 In the rare case where one wants to create a watcher but not start it at 149 In the rare case where one wants to create a watcher but not start it at
145 the same time, each constructor has a variant with a trailing "_ns" in 150 the same time, each constructor has a variant with a trailing "_ns" in
163 stopped watchers). 168 stopped watchers).
164 169
165 $w->stop 170 $w->stop
166 Stop a watcher if it is active. Also clear any pending events 171 Stop a watcher if it is active. Also clear any pending events
167 (events that have been received but that didn't yet result in a 172 (events that have been received but that didn't yet result in a
168 callback invocation), regardless of wether the watcher was active or 173 callback invocation), regardless of whether the watcher was active
169 not. 174 or not.
170 175
171 $bool = $w->is_active 176 $bool = $w->is_active
172 Returns true if the watcher is active, false otherwise. 177 Returns true if the watcher is active, false otherwise.
173 178
174 $current_data = $w->data 179 $current_data = $w->data
223 returning. 228 returning.
224 229
225 The initial value for keepalive is true (enabled), and you cna 230 The initial value for keepalive is true (enabled), and you cna
226 change it any time. 231 change it any time.
227 232
228 Example: Register an IO watcher for some UDP socket but do not keep 233 Example: Register an I/O watcher for some UDP socket but do not keep
229 the event loop from running just because of that watcher. 234 the event loop from running just because of that watcher.
230 235
231 my $udp_socket = ... 236 my $udp_socket = ...
232 my $udp_watcher = EV::io $udp_socket, EV::READ, sub { ... }; 237 my $udp_watcher = EV::io $udp_socket, EV::READ, sub { ... };
233 $udp_watcher->keepalive (0); 238 $udp_watcher->keepalive (0);
234 239
235 WATCHER TYPES 240 WATCHER TYPES
236 Each of the following subsections describes a single watcher type. 241 Each of the following subsections describes a single watcher type.
237 242
238 IO WATCHERS - is this file descriptor readable or writable? 243 I/O WATCHERS - is this file descriptor readable or writable?
239 $w = EV::io $fileno_or_fh, $eventmask, $callback 244 $w = EV::io $fileno_or_fh, $eventmask, $callback
240 $w = EV::io_ns $fileno_or_fh, $eventmask, $callback 245 $w = EV::io_ns $fileno_or_fh, $eventmask, $callback
241 As long as the returned watcher object is alive, call the $callback 246 As long as the returned watcher object is alive, call the $callback
242 when at least one of events specified in $eventmask occurs. 247 when at least one of events specified in $eventmask occurs.
243 248
468 resource-intensive. 473 resource-intensive.
469 474
470 The "stat_ns" variant doesn't start (activate) the newly created 475 The "stat_ns" variant doesn't start (activate) the newly created
471 watcher. 476 watcher.
472 477
478 ... = $w->stat
479 This call is very similar to the perl "stat" built-in: It stats
480 (using "lstat") the path specified in the watcher and sets perls
481 stat cache (as well as EV's idea of the current stat values) to the
482 values found.
483
484 In scalar context, a boolean is return indicating success or failure
485 of the stat. In list context, the same 13-value list as with stat is
486 returned (except that the blksize and blocks fields are not
487 reliable).
488
489 In the case of an error, errno is set to "ENOENT" (regardless of the
490 actual error value) and the "nlink" value is forced to zero (if the
491 stat was successful then nlink is guaranteed to be non-zero).
492
493 See also the next two entries for more info.
494
495 ... = $w->attr
496 Just like "$w->stat", but without the initial stat'ing: this returns
497 the values most recently detected by EV. See the next entry for more
498 info.
499
500 ... = $w->prev
501 Just like "$w->stat", but without the initial stat'ing: this returns
502 the previous set of values, before the change.
503
504 That is, when the watcher callback is invoked, "$w->prev" will be
505 set to the values found *before* a change was detected, while
506 "$w->attr" returns the values found leading to the change detection.
507 The difference (if any) between "prev" and "attr" is what triggered
508 the callback.
509
510 If you did something to the filesystem object and do not want to
511 trigger yet another change, you can call "stat" to update EV's idea
512 of what the current attributes are.
513
473 $w->set ($path, $interval) 514 $w->set ($path, $interval)
474 Reconfigures the watcher, see the constructor above for details. Can 515 Reconfigures the watcher, see the constructor above for details. Can
475 be called at any time. 516 be called at any time.
476 517
477 $current_path = $w->path 518 $current_path = $w->path
484 Can be used to query the actual interval used. 525 Can be used to query the actual interval used.
485 526
486 IDLE WATCHERS - when you've got nothing better to do... 527 IDLE WATCHERS - when you've got nothing better to do...
487 $w = EV::idle $callback 528 $w = EV::idle $callback
488 $w = EV::idle_ns $callback 529 $w = EV::idle_ns $callback
489 Call the callback when there are no pending io, timer/periodic, 530 Call the callback when there are no other pending watchers of the
490 signal or child events, i.e. when the process is idle. 531 same or higher priority (excluding check, prepare and other idle
532 watchers of the same or lower priority, of course). They are called
533 idle watchers because when the watcher is the highest priority
534 pending event in the process, the process is considered to be idle
535 at that priority.
536
537 If you want a watcher that is only ever called when *no* other
538 events are outstanding you have to set the priority to "EV::MINPRI".
491 539
492 The process will not block as long as any idle watchers are active, 540 The process will not block as long as any idle watchers are active,
493 and they will be called repeatedly until stopped. 541 and they will be called repeatedly until stopped.
542
543 For example, if you have idle watchers at priority 0 and 1, and an
544 I/O watcher at priority 0, then the idle watcher at priority 1 and
545 the I/O watcher will always run when ready. Only when the idle
546 watcher at priority 1 is stopped and the I/O watcher at priority 0
547 is not pending with the 0-priority idle watcher be invoked.
494 548
495 The "idle_ns" variant doesn't start (activate) the newly created 549 The "idle_ns" variant doesn't start (activate) the newly created
496 watcher. 550 watcher.
497 551
498 PREPARE WATCHERS - customise your event loop! 552 PREPARE WATCHERS - customise your event loop!
527 or return; 581 or return;
528 582
529 # make the dispatcher handle any outstanding stuff 583 # make the dispatcher handle any outstanding stuff
530 ... not shown 584 ... not shown
531 585
532 # create an IO watcher for each and every socket 586 # create an I/O watcher for each and every socket
533 @snmp_watcher = ( 587 @snmp_watcher = (
534 (map { EV::io $_, EV::READ, sub { } } 588 (map { EV::io $_, EV::READ, sub { } }
535 keys %{ $dispatcher->{_descriptors} }), 589 keys %{ $dispatcher->{_descriptors} }),
536 590
537 EV::timer +($event->[Net::SNMP::Dispatcher::_ACTIVE] 591 EV::timer +($event->[Net::SNMP::Dispatcher::_ACTIVE]
570 Call the callback before the event loop is resumed in the child 624 Call the callback before the event loop is resumed in the child
571 process after a fork. 625 process after a fork.
572 626
573 The "fork_ns" variant doesn't start (activate) the newly created 627 The "fork_ns" variant doesn't start (activate) the newly created
574 watcher. 628 watcher.
629
630PERL SIGNALS
631 While Perl signal handling (%SIG) is not affected by EV, the behaviour
632 with EV is as the same as any other C library: Perl-signals will only be
633 handled when Perl runs, which means your signal handler might be invoked
634 only the next time an event callback is invoked.
635
636 The solution is to use EV signal watchers (see "EV::signal"), which will
637 ensure proper operations with regards to other event watchers.
638
639 If you cannot do this for whatever reason, you can also force a watcher
640 to be called on every event loop iteration by installing a "EV::check"
641 watcher:
642
643 my $async_check = EV::check sub { };
644
645 This ensures that perl shortly gets into control for a short time, and
646 also ensures slower overall operation.
575 647
576THREADS 648THREADS
577 Threads are not supported by this module in any way. Perl pseudo-threads 649 Threads are not supported by this module in any way. Perl pseudo-threads
578 is evil stuff and must die. As soon as Perl gains real threads I will 650 is evil stuff and must die. As soon as Perl gains real threads I will
579 work on thread support for it. 651 work on thread support for it.
594 666
595 On win32, there is no notion of fork so all this doesn't apply, of 667 On win32, there is no notion of fork so all this doesn't apply, of
596 course. 668 course.
597 669
598SEE ALSO 670SEE ALSO
599 EV::DNS. 671 EV::ADNS (asynchronous dns), Glib::EV (makes Glib/Gtk2 use EV as event
672 loop), Coro::EV (efficient coroutines with EV).
600 673
601AUTHOR 674AUTHOR
602 Marc Lehmann <schmorp@schmorp.de> 675 Marc Lehmann <schmorp@schmorp.de>
603 http://home.schmorp.de/ 676 http://home.schmorp.de/
604 677

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines