Linux::Epoll(3pm)
π Linux::Epoll β the manual, but make it cute π
okay bestie, you found it: the Linux::Epoll page from the User Contributed Perl Documentation section of the manual. it's giving callback-style epoll for Linux, and honestly? iconic. let's get into it π«Ά
β¨ NAME β¨
Linux::Epoll β O(1) multiplexing for Linux, no cap π
πΈ VERSION πΈ
version 0.019 β that's the vibe check, and it passed β
π¦ SYNOPSIS π¦
okay so literally all you need to start:
use Linux::Epoll;
my $epoll = Linux::Epoll->new();
$epoll->add($fh, 'in', sub {
my $events = shift;
do_something($fh) if $events->{in};
});
$epoll->wait while 1;
look at her. main character energy fr fr π₯
π DESCRIPTION π
So epoll is a multiplexing mechanism that scales up O(1) with the number of watched files β like, it does NOT get slower as you add more files, she just eats πβ¨
Linux::Epoll is a callback style epoll module, which is the whole point, because unlike the other epoll modules on CPAN, this one hands you callbacks instead of making you do the whole loop yourself. different breed.
π Types of events π
here's the menu of event flags, and every single one matters, don't skip:
inβ the associated filehandle is available for reading πoutβ the associated filehandle is available for writing βοΈerrβ an error condition happened on the associated filehandle. heads up:waitalways waits on this event, so you do NOT have to set it yourself withaddormodify. she shows up uninvited πprioβ there's urgent data available for reading π¨etβ sets edge triggered behavior for the associated filehandle. the default behavior is level triggered. go check yourepoll(7)documentation for what that actually means, i'm not doing that for you π§
β οΈ take note bestie: when you're using edge triggered events, exceptions thrown out of the wait can easily cause events to be lost (specifically when you're consuming more than one event at a time). this is the dangerous one. be careful. π
hupβ a hang-up happened on the associated filehandle. same deal aserr:waitalways waits on this, so no need to set it withaddormodifyπrdhupβ the stream socket peer closed the connection, or shut down the writing half of it. this flag is especially useful for writing simple code to detect peer shutdown when you're using Edge Triggered monitoring πoneshotβ sets the one-shot behavior for the associated file descriptor. what that means: after an event gets pulled out withwait, the associated file descriptor is internally disabled and no other events will be reported by the epoll interface. so you, the user, have to callmodifyto rearm the file descriptor with a new event mask. one and done, periodt βwakeupβ ifoneshotandetare clear and the process has theCAP_BLOCK_SUSPENDcapability, this ensures the system does not entersuspendorhibernatewhile this event is pending or being processed. and "processed" here has a very specific meaning: the event counts as processed from the time it is returned by a call toepoll_wait(2)until the next call toepoll_wait(2)on the sameepoll(7)file descriptor β OR the closure of that file descriptor, OR the removal of the event file descriptor withEPOLL_CTL_DEL, OR the clearing ofEPOLLWAKEUPfor the event file descriptor withEPOLL_CTL_MOD. four ways to end it, slay πexclusiveβ sets an exclusive wakeup mode for the epoll file descriptor that is being attached to the target file descriptor,fd. here's the tea: when a wakeup event occurs and multiple epoll file descriptors are attached to the same target file usingexclusive, then one or more of those epoll file descriptors will receive an event withwait(). the default, i.e. whenexclusiveis not set, is that all epoll file descriptors receive an event. soexclusiveis useful for avoiding thundering herd problems in certain scenarios. you know the ones. πππ
and if the same file descriptor is in multiple epoll instances β some with the exclusive flag, some without β then events get provided to all the epoll instances that did not specify exclusive, and at least one of the epoll instances that did specify exclusive.
the following values may be specified in conjunction with exclusive: in, out, wakeup, and et. hup and err can also be specified, but that is not required β as usual, these events are always reported if they occur, regardless of whether they're specified in events. attempts to specify other values in events yield an error. and listen: exclusive may be used only in an add() operation β attempts to employ it with modify yield an error. if exclusive has been set using add(), then a subsequent modify() on the same epfd, fd pair yields an error. and a call to add( that specifies exclusive in events and specifies the target file descriptor fd as an epoll instance will likewise fail. the error in all of these cases is EINVAL. every single one. EINVAL. π€
π METHODS π
β new()
Create a new epoll instance. that's it, that's the method. baby's first epoll β¨
β add($fh, $events, $callback)
Register the filehandle with the epoll instance and associate events $events and callback $callback with it. $events may be either a string (e.g. 'in') or an arrayref (e.g. [qw/in out hup/]). versatile queen π
if a filehandle already exists in the set and add is called in non-void context, it returns undef and sets $! to EEXIST. if the file can't be waited upon, it sets $! to EPERM instead. on all other error conditions, an exception is thrown π©
the callback gets a single argument: a hashref whose keys are the triggered events. yes, one argument. yes, it's a hashref. memorize it π«Ά
β modify($fh, $events, $callback)
Change the events and callback associated on this epoll instance with filehandle $fh. the arguments work the same as with add. glow-up for an existing registration π
if a filehandle doesn't exist in the set and modify is called in non-void context, it returns undef and sets $! to ENOENT. on all other error conditions, an exception is thrown.
β delete($fh)
Remove a filehandle from the epoll instance. blocking that number, blocking that number π΅
if a filehandle doesn't exist in the set and delete is called in non-void context, it returns undef and sets $! to ENOENT. on all other error conditions, an exception is thrown.
β wait($number = 1, $timeout = undef, $sigmask = undef)
Wait for up to $number events, where $number must be greater than zero (don't test her). $timeout is the maximal time wait will wait for events, in fractional seconds. if it is undefined, she may wait indefinitely β no thoughts, head empty, just vibes π $sigmask is the signal mask during the call; if it is not defined the signal mask will be untouched.
if interrupted by a signal it returns undef / an empty list and sets $! to EINTR. on all other error conditions, an exception is thrown.
π REQUIREMENTS π
this module requires at least Perl 5.10 and Linux 2.6.19 to function correctly. old heads welcome, but not too old π§β¨
π₯ SEE ALSO π₯
go read these too, i'm obsessed with all of them:
IO::EpollSys::SyscallIO::Poll
πΈ AUTHOR πΈ
Leon Timmermans <leont@cpan.org> β the icon, the legend, the moment π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2010 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in bestie, go wild π
and that's the whole page, babe π this one came out of perl v5.42.3, dated 2026-08-19, living in the Linux::Epoll(3pm) section of your manual. now go write some O(1) callbacks and text me when it works. slay π
β¨π«Ά
π¦ where this page comes from
- ubuntu stonking: liblinux-epoll-perl 0.019-1build4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms