NAME
Linux::Event::Watcher - Mutable readiness watcher handle for Linux::Event::Loop
SYNOPSIS
use v5.36;
use Linux::Event;
my $loop = Linux::Event->new;
my $watcher = $loop->watch(
$fh,
read => sub ($loop, $fh, $watcher) {
my $buf = '';
my $n = sysread($fh, $buf, 8192);
if (!defined $n || $n == 0) {
$watcher->cancel;
close $fh;
return;
}
# ... handle $buf ...
},
write => sub ($loop, $fh, $watcher) {
# fd became writable
$watcher->disable_write;
},
error => sub ($loop, $fh, $watcher) {
# error readiness reported
$watcher->cancel;
close $fh;
},
);
$watcher->disable_read;
$watcher->enable_read;
$watcher->cancel;
DESCRIPTION
Linux::Event::Watcher is the lightweight handle returned by "watch" in Linux::Event::Loop. 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])
Get or replace the read callback.
on_write([$cb])
Get or replace the write callback.
on_error([$cb])
Get or replace the error callback.
enable_read, disable_read
Enable or disable read readiness dispatch for this watcher.
enable_write, disable_write
Enable or disable write readiness dispatch for this watcher.
enable_error, disable_error
Enable or disable error readiness dispatch for this watcher.
read_enabled, write_enabled, error_enabled
Return true when the corresponding readiness callback is enabled.
cancel
Remove the watcher from the loop.
CALLBACK ABI
Watcher callbacks receive:
$cb->($loop, $fh, $watcher)
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.011.