```{index} single: Event::io ``` # Event::io ```{pperl-module-badges} Event::io ``` An io watcher: an event when a file descriptor is ready to read or to write, or has an exception pending - and, optionally, when it has been quiet for a given time. Its events are `Event::Event::Io` objects, whose `got` says what happened. `Event->io(%attributes)` (or `Event::io->new(...)`) takes the shared attributes of `Event::Watcher` and the ones below. An io watcher repeats, and stays registered while its callback runs. Its default priority is `PRIO_NORMAL`. It refuses to start without a callback ("without io callback"), and with neither a descriptor to poll nor a timeout ("because there is nothing to watch"). One watcher can watch for several conditions, or several watchers can share a descriptor; both work. The bit constants `R`, `W`, `E` and `T` can be imported from `Event::io` as well as from `Event::Watcher`. ## Synopsis ```perl use Event; Event->io(fd => \*STDIN, poll => 'r', timeout => 30, cb => sub { my $e = shift; if ($e->got =~ /t/) { print "30 seconds without input\n"; return } defined(my $line = ) or return Event::unloop(); print "read: $line"; }); Event::loop(); ``` ## Functions ### Attributes #### `poll` What to wait for: a string of the letters `r` (read), `w` (write) and `e` (exception), or the number made of the bits `R`, `W` and `E`; `"r"` by default. Another letter warns "Ignored 'x' in poll mask" and other bits warn too. The value returned is both the string and the number. It includes `t` exactly when a `timeout` is set, whatever was asked. #### `fd` The descriptor to watch: a glob or glob reference (`\*STDIN`, an `IO::Handle` object), or a file descriptor number. Its descriptor is taken when the watcher starts; a glob without an open handle dies "isn't a valid IO", anything else "can't find fileno". #### `timeout` Seconds without a callback after which an event comes anyway, with `t` in its `got`; 0 or undef (the default) for none. Each callback restarts the count. A watcher that does not repeat fires the timeout once and then clears it. #### `timeout_cb` The callback for timeouts, in the forms `cb` takes; while it is undef (the default), timeouts go to `cb` too. Unlike `cb`, a `[$object, $method_name]` naming a method that does not exist is taken without a warning.