Linux::Event::Listen
Listening sockets for Linux::Event, supporting both TCP and UNIX domain sockets.
Install
cpanm Linux::Event::Listen
Usage (TCP)
use v5.36;
use Linux::Event;
use Linux::Event::Listen;
my $loop = Linux::Event->new;
my $listen = Linux::Event::Listen->new(
loop => $loop,
host => '127.0.0.1',
port => 3000,
on_accept => sub ($loop, $client_fh, $peer, $listen) {
# You own $client_fh (already non-blocking).
...
},
);
$loop->run;
Usage (UNIX)
my $listen = Linux::Event::Listen->new(
loop => $loop,
path => '/tmp/app.sock',
unlink => 1,
on_accept => sub ($loop, $client_fh, $peer, $listen) {
...
},
);
Guarantees and semantics
- Drains
accept()untilEAGAINwhen edge-triggered readiness is used. max_accept_per_ticklimits work per callback to avoid starving other watchers.- If
max_accept_per_tickis explicitly set andedge_triggeredis not, the listener defaults to level-triggered readiness to avoid edge-trigger stalls. - Accepted sockets are set non-blocking and handed to user code; you own them.
cancel()is safe to call from insideon_accept(listener close may be deferred until the callback returns).
Error handling
on_errorreceives a hashref describing the condition (op,error, optionalerrno).on_emfileis invoked forEMFILE/ENFILEaccept failures (useful for reserve-FD mitigation).
UNIX socket lifecycle
unlink => 1removes an existing path before binding.unlink_on_canceldefaults true for internally-created UNIX sockets; wrap mode (fh => ...) will not unlink paths unlesspathwas provided.
See the POD in Linux::Event::Listen for full details.