```{index} single: io (EV) ``` ```{index} single: EV::io ``` ```{index} single: EV::io_ns ``` # io Watch a file handle: call the callback whenever it is readable or writable without blocking. Also available as `EV::io_ns`. ## Synopsis ```perl my $w = EV::io $fh_or_fileno, EV::READ, sub { my ($w, $revents) = @_; ... }; my $s = EV::io_ns $sock, EV::READ | EV::WRITE, sub { ... }; # not started ``` ## What you get back An `EV::IO` watcher, active (except from `EV::io_ns`) as long as the object lives. The callback gets the watcher and the events that occurred, `EV::READ`, `EV::WRITE` or both. ## Examples Read lines as they arrive: ```perl my $w = EV::io *STDIN, EV::READ, sub { defined(my $line = ) or return EV::break; print "got: $line"; }; EV::run; ``` ## Edge cases - The handle may be a Perl file handle or a file descriptor number. One without a descriptor croaks `illegal file descriptor or filehandle`. - EV tells when the descriptor is ready, not whether Perl's buffered handle has data: read with `sysread` (or one line per event, as above) so that buffered data is not left waiting. - Several watchers may watch one descriptor. ## Differences from upstream Fully compatible with upstream. Covered by `t/81-xs-native/EV/190-upstream-09_brandon.t`. ## See also - `EV::IO` - change the handle or the events of a watcher - `EV::once` - wait for one event without keeping a watcher