IO::Epoll(3pm)
π IO::Epoll π
okay bestie, so this whole page is about IO::Epoll β Scalable IO Multiplexing for Linux 2.5.44 and higher. yes that's the name, and yes it's lowkey iconic. it lives in the User Contributed Perl Documentation, and this is literally the IO::Epoll(3pm) page. let's get into it π¦
β¨ SYNOPSIS β¨
# Low level interface
use IO::Epoll;
$epfd = epoll_create(10);
epoll_ctl($epfd, EPOLL_CTL_ADD, fileno STDIN, EPOLLIN) >= 0
|| die "epoll_ctl: $!\n";
epoll_ctl($epfd, ...);
$events = epoll_wait($epfd, 10, 1000); # Max 10 events returned, 1s timeout
# High level IO::Poll emulation layer
use IO::EPoll qw(:compat);
$poll = new IO::Epoll;
$poll->mask($input_handle => POLLIN);
$poll->mask($output_handle => POLLOUT);
$poll->poll($timeout);
$ev = $poll->events($input);
(and yes, notice the use IO::EPoll qw(:compat); casing up there β that's verbatim, don't come for me, copy it exactly as shown π
)
π DESCRIPTION π
so the epoll(4) subsystem is a new β and currently Linux-specific β variant of poll(2). it's giving scalabilitea. it's designed to offer O(1) scalability over large numbers of watched file descriptors. you will need at least version 2.5.44 of Linux to use this module, and you might need to upgrade your C library. heads up bestie, that's a real requirement, not a vibe β¨
the epoll(2) API comprises four system calls: epoll_create(2), epoll_ctl(2), epoll_wait(2) and epoll_pwait(2). IO::Epoll provides a low-level API which closely matches the underlying system calls. it also provides a higher-level layer designed to emulate the behavior of IO::Poll and IO::Ppoll. dual threat. main character energy honestly π
π₯ LOW-LEVEL API π₯
π epoll_create π
creates a new epoll file descriptor by requesting the kernel allocate an event backing store dimensioned for size descriptors. and no, size is not the maximum size of the backing store β it's literally just a hint to the kernel about how to dimension internal structures. (the kernel is the one making the decisions here, we're just giving suggestions π
) the returned file descriptor will be used for all the subsequent calls to the epoll interface. and the file descriptor returned by epoll_create must be closed by using POSIX::close.
$epfd = epoll_create(15);
...
POSIX::close($epfd);
when successful, epoll_create returns a positive integer identifying the descriptor. when an error occurs, it returns -1 and errno is set appropriately. π
π¦ epoll_ctl π¦
controls an epoll descriptor, $epfd, by requesting the operation op be performed on the target file descriptor, fd.
$ret = epoll_ctl($epfd, $op, $fd, $eventmask)
- $epfd is an
epolldescriptor returned fromepoll_create. - $op is one of
EPOLL_CTL_ADD,EPOLL_CTL_MODorEPOLL_CTL_DEL. - $fd is the file descriptor to be watched.
- $eventmask is a bitmask of events defined by
EPOLLIN,EPOLLOUT, etc.
when successful, epoll_ctl returns 0. when an error occurs, it returns -1 and errno is set appropriately. periodt.
π epoll_wait π
waits for events on the epoll file descriptor $epfd.
$ret = epoll_wait($epfd, $maxevents, $timeout)
- $epfd is an
epolldescriptor returned fromepoll_create. - $maxevents is an integer specifying the maximum number of events to be returned.
- $timeout is a timeout, in milliseconds
when successful, epoll_wait returns a reference to an array of events. each event is a two element array: the first element is the file descriptor which triggered the event, and the second is the mask of event types triggered. for example, if epoll_wait returned the following data structure:
[
[ 0, EPOLLIN ],
[ 6, EPOLLOUT | EPOLLIN ]
]
then file descriptor 0 would be ready for reading, and fd 4 would be ready for both reading and writing.
on error, epoll_wait returns undef and sets errno appropriately. π
πΈ epoll_pwait πΈ
waits for events on the epoll file descriptor $epfd.
$ret = epoll_pwait($epfd, $maxevents, $timeout, $sigmask)
identical to epoll_wait, except that the kernel will atomically swap the current signal mask for the process to that supplied in $sigmask, wait for events, then restore it to what it was originally. so clean, so tidy, obsessed π«Ά the $sigmask parameter should be undef, or an instance of POSIX::SigSet.
β HIGH LEVEL API β
IO::Epoll provides an object oriented API designed to be a drop-in replacement for IO::Poll. go read the documentation for that module for more information, iykyk.
π METHODS π
mask ( IO [, EVENT_MASK ] )β if EVENT_MASK is given, then, if EVENT_MASK is non-zero, IO is added to the list of file descriptors and the next call to poll will check for any event specified in EVENT_MASK. if EVENT_MASK is zero then IO will be removed from the list of file descriptors.
if EVENT_MASK is not given then the return value will be the current event mask value for IO.
poll ( [ TIMEOUT ] )β call the system level poll routine. if TIMEOUT is not specified then the call will block. returns the number of handles which had events happen, or -1 on error. TIMEOUT is in seconds and may be fractional. (fractional?? she's flexible, we love that π )events ( IO )β returns the event mask which represents the events that happened on IO during the last call topoll.remove ( IO )β remove IO from the list of file descriptors for the next poll.handles( [ EVENT_MASK ] )β returns a list of handles. if EVENT_MASK is not given then a list of all handles known will be returned. if EVENT_MASK is given then a list of handles will be returned which had one of the events specified by EVENT_MASK happen during the last call topoll.
π§ IO::Ppoll METHODS π§
IO::Epoll also provides methods compatible with IO::Ppoll. the way that works: when any of these methods are called, the IO::Epoll object switches up to IO::Ppoll-compatible mode, and will use the epoll_pwait(2) system call when the poll method is invoked. it's a whole glow-up β¨
sigmaskβ returns thePOSIX::SigSetobject in which the signal mask is stored. since this is a reference to the object used in the call toepoll_pwait(2), any modifications made to it will be reflected in the signal mask given to the system call. (yes bestie, it's live β edits show up everywhere, no cap.)sigmask_add ( SIGNALS )β adds the given signals to the signal mask. these signals will be blocked during thepollcall.sigmask_del ( SIGNALS )β removes the given signals from the signal mask. these signals will not be blocked during thepollcall, and may be delivered whilepollis waiting.sigmask_ismember ( SIGNAL )β tests if the given signal is present in the signal mask.
π Exportable constants π
exported by default:
EPOLLERR
EPOLLET
EPOLLHUP
EPOLLIN
EPOLLMSG
EPOLLOUT
EPOLLPRI
EPOLLRDBAND
EPOLLRDNORM
EPOLLWRBAND
EPOLLWRNORM
EPOLL_CTL_ADD
EPOLL_CTL_DEL
EPOLL_CTL_MOD
exported by the :compat tag:
POLLNVAL
POLLIN
POLLOUT
POLLERR
POLLHUP
POLLPRI
POLLRDNORM
POLLWRNORM
POLLRDBAND
POLLWRBAND
π SEE ALSO π
IO::Poll IO::Select IO::Ppoll epoll(4) epoll_create(2) epoll_ctl(2) epoll_wait(2) epoll_pwait(2)
π AUTHOR π
Bruce J Keeler, <bruce@gridpoint.com>
π CREDITS π
the IO::Poll compatibility code borrows heavily from the IO::Poll code itself, which was written by Graham Barr. giving credit where credit is due, as we always do π«Ά
β COPYRIGHT AND LICENSE β
Copyright (C) 2004 by Bruce J. Keeler Portions Copyright (C) 1997-8 Graham Barr <gbarr@pobox.com>
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page bestie, you ate π
the version on this is perl v5.42.3, dated 2026-08-19, and it's filed under IO::Epoll(3pm) β mwah, go build something scalable π¦πΈβ¨
π¦ where this page comes from
- ubuntu stonking: libio-epoll-perl 0.03-3build6 Β· 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