… | |
… | |
208 | If timeout is C<undef> or negative, then there will be no |
208 | If timeout is C<undef> or negative, then there will be no |
209 | timeout. Otherwise a EV::timer with this value will be started. |
209 | timeout. Otherwise a EV::timer with this value will be started. |
210 | |
210 | |
211 | When an error occurs or either the timeout or I/O watcher triggers, then |
211 | When an error occurs or either the timeout or I/O watcher triggers, then |
212 | the callback will be called with the received event set (in general |
212 | the callback will be called with the received event set (in general |
213 | you can expect it to be a combination of C<EV:ERROR>, C<EV::READ>, |
213 | you can expect it to be a combination of C<EV::ERROR>, C<EV::READ>, |
214 | C<EV::WRITE> and C<EV::TIMEOUT>). |
214 | C<EV::WRITE> and C<EV::TIMEOUT>). |
215 | |
215 | |
216 | EV::once doesn't return anything: the watchers stay active till either |
216 | EV::once doesn't return anything: the watchers stay active till either |
217 | of them triggers, then they will be stopped and freed, and the callback |
217 | of them triggers, then they will be stopped and freed, and the callback |
218 | invoked. |
218 | invoked. |
… | |
… | |
239 | event. For instance, if you want to wait for STDIN to become readable, you |
239 | event. For instance, if you want to wait for STDIN to become readable, you |
240 | would create an EV::io watcher for that: |
240 | would 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 | |
247 | All watchers can be active (waiting for events) or inactive (paused). Only |
247 | All watchers can be active (waiting for events) or inactive (paused). Only |
248 | active watchers will have their callbacks invoked. All callbacks will be |
248 | active watchers will have their callbacks invoked. All callbacks will be |
249 | called with at least two arguments: the watcher and a bitmask of received |
249 | called with at least two arguments: the watcher and a bitmask of received |
… | |
… | |
333 | Feed some events on this watcher into EV. EV will react to this call as if |
333 | 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. |
334 | the watcher had received the given C<$revents> mask. |
335 | |
335 | |
336 | =item $revents = $w->clear_pending |
336 | =item $revents = $w->clear_pending |
337 | |
337 | |
338 | If the watcher is pending, this function returns clears its pending status |
338 | 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 |
339 | 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>. |
340 | watcher isn't pending it does nothing and returns C<0>. |
341 | |
341 | |
342 | =item $previous_state = $w->keepalive ($bool) |
342 | =item $previous_state = $w->keepalive ($bool) |
343 | |
343 | |
344 | Normally, C<EV::loop> will return when there are no active watchers |
344 | Normally, C<EV::loop> will return when there are no active watchers |
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 |
346 | convinient because it allows you to start your watchers (and your jobs), |
346 | convinient because it allows you to start your watchers (and your jobs), |
347 | call C<EV::loop> once and when it returns you know that all your jobs are |
347 | call C<EV::loop> once and when it returns you know that all your jobs are |
348 | finished (or they forgot to register some watchers for their task :). |
348 | finished (or they forgot to register some watchers for their task :). |
349 | |
349 | |
350 | Sometimes, however, this gets in your way, for example when you the module |
350 | Sometimes, however, this gets in your way, for example when the module |
351 | that calls C<EV::loop> (usually the main program) is not the same module |
351 | that calls C<EV::loop> (usually the main program) is not the same module |
352 | as a long-living watcher (for example a DNS client module written by |
352 | as a long-living watcher (for example a DNS client module written by |
353 | somebody else even). Then you might want any outstanding requests to be |
353 | somebody else even). Then you might want any outstanding requests to be |
354 | handled, but you would not want to keep C<EV::loop> from returning just |
354 | handled, but you would not want to keep C<EV::loop> from returning just |
355 | because you happen to have this long-running UDP port watcher. |
355 | because you happen to have this long-running UDP port watcher. |
… | |
… | |
384 | |
384 | |
385 | =item $w = EV::io $fileno_or_fh, $eventmask, $callback |
385 | =item $w = EV::io $fileno_or_fh, $eventmask, $callback |
386 | |
386 | |
387 | =item $w = EV::io_ns $fileno_or_fh, $eventmask, $callback |
387 | =item $w = EV::io_ns $fileno_or_fh, $eventmask, $callback |
388 | |
388 | |
389 | =item $w = $loop->io 8$fileno_or_fh, $eventmask, $callback) |
389 | =item $w = $loop->io ($fileno_or_fh, $eventmask, $callback) |
390 | |
390 | |
391 | =item $w = $loop->io_ns ($fileno_or_fh, $eventmask, $callback) |
391 | =item $w = $loop->io_ns ($fileno_or_fh, $eventmask, $callback) |
392 | |
392 | |
393 | As long as the returned watcher object is alive, call the C<$callback> |
393 | As long as the returned watcher object is alive, call the C<$callback> |
394 | when at least one of events specified in C<$eventmask> occurs. |
394 | when at least one of events specified in C<$eventmask> occurs. |
… | |
… | |
791 | |
791 | |
792 | =item $w = EV::prepare_ns $callback |
792 | =item $w = EV::prepare_ns $callback |
793 | |
793 | |
794 | =item $w = $loop->prepare ($callback) |
794 | =item $w = $loop->prepare ($callback) |
795 | |
795 | |
796 | =item $w = $loop->prepare_ns 8$callback) |
796 | =item $w = $loop->prepare_ns ($callback) |
797 | |
797 | |
798 | Call the callback just before the process would block. You can still |
798 | Call the callback just before the process would block. You can still |
799 | create/modify any watchers at this point. |
799 | create/modify any watchers at this point. |
800 | |
800 | |
801 | See the EV::check watcher, below, for explanations and an example. |
801 | See the EV::check watcher, below, for explanations and an example. |
… | |
… | |
906 | to be called on every event loop iteration by installing a C<EV::check> |
906 | to be called on every event loop iteration by installing a C<EV::check> |
907 | watcher: |
907 | watcher: |
908 | |
908 | |
909 | my $async_check = EV::check sub { }; |
909 | my $async_check = EV::check sub { }; |
910 | |
910 | |
911 | This ensures that perl shortly gets into control for a short time, and |
911 | This ensures that perl gets into control for a short time to handle any |
912 | also ensures slower overall operation. |
912 | pending signals, and also ensures (slightly) slower overall operation. |
913 | |
913 | |
914 | =head1 THREADS |
914 | =head1 THREADS |
915 | |
915 | |
916 | Threads are not supported by this module in any way. Perl pseudo-threads |
916 | Threads are not supported by this module in any way. Perl pseudo-threads |
917 | is evil stuff and must die. As soon as Perl gains real threads I will work |
917 | is evil stuff and must die. As soon as Perl gains real threads I will work |