NAME
Linux::Event::Watcher - Mutable readiness watcher handle for Linux::Event::Reactor
SYNOPSIS
<<<<<<< HEAD my $watcher = $loop->watch( $fh, read => sub ($loop, $fh, $watcher) { ... ======= use v5.36; use Linux::Event;
my $loop = Linux::Event->new( model => 'reactor' );
my $w = $loop->watch($fh,
read => sub ($loop, $fh, $w) {
my $buf;
my $n = sysread($fh, $buf, 8192);
if (!defined $n || $n == 0) {
$w->cancel;
close $fh;
return;
}
# ... handle $buf ...
},
write => sub ($loop, $fh, $w) {
# fd became writable
$w->disable_write; # typical: only enable when you actually have pending output
},
error => sub ($loop, $fh, $w) {
# error readiness reported (see DISPATCH SEMANTICS)
$w->cancel;
close $fh;
>>>>>>> 1401c31 (prep for cpan and release, new tool added)
},
);
$watcher->disable_read;
$watcher->enable_read;
$watcher->cancel;
DESCRIPTION
Linux::Event::Watcher is the lightweight handle returned by "watch" in Linux::Event::Reactor. It stores the current callbacks, enablement flags, filehandle metadata, and a user data slot.
The watcher does not own backend policy. Methods that change interest state simply delegate back into the loop.
METHODS
loop, fh, fd
Basic accessors.
is_active
True while the watcher is still registered with the loop.
data([$new])
Get or set the user data slot.
edge_triggered([$bool])
Get or set edge-triggered mode.
oneshot([$bool])
Get or set one-shot mode.
on_read([$cb])
on_write([$cb])
on_error([$cb])
Install or replace callbacks.
enable_read, disable_read
enable_write, disable_write
enable_error, disable_error
Toggle callback enablement.
cancel
Remove the watcher from the loop.
CALLBACK ABI
Watcher callbacks receive:
<<<<<<< HEAD $cb->($loop, $fh, $watcher) ======= =head2 Error readiness ordering
If an epoll event indicates an error condition (for example EPOLLERR), the loop dispatches to the watcher's error callback first (if installed and enabled) and returns.
If no error callback is installed/enabled, error readiness may be treated as readable and/or writable (depending on the platform and backend behavior). Do not rely on a specific fallback; install an error handler if you want explicit error handling.
Hangup / EOF
On hangup conditions (for example EPOLLHUP), readable readiness is typically delivered so user code can observe EOF via read(2) returning 0.
VERSION
This document describes Linux::Event::Watcher version 0.009. >>>>>>> 1401c31 (prep for cpan and release, new tool added)