IO::As...:Epoll(3pm)

πŸ“¦
version 0.23 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– IO::Async::Loop::Epoll β€” the manual, but make it make sense πŸ’–

okay so bestie, this page is IO::Async::Loop::Epoll(3pm), from the User Contributed Perl Documentation corner of the world. it's giving linux-girlie performance magic, and honestly? obsessed.


✨ NAME ✨

"IO::Async::Loop::Epoll" β€” it's how you use "IO::Async" with "epoll" on Linux. that's the whole vibe. 🐧


🌸 SYNOPSIS 🌸

here's the little starter pack, verbatim, no notes:

use IO::Async::Loop::Epoll;

use IO::Async::Stream;
use IO::Async::Signal;

my $loop = IO::Async::Loop::Epoll->new;

$loop->add( IO::Async::Stream->new(
      read_handle => \*STDIN,
      on_read => sub {
         my ( $self, $buffref ) = @_;
         while( $$buffref =~ s/^(.*)\r?\n// ) {
            print "You said: $1\n";
         }
      },
) );

$loop->add( IO::Async::Signal->new(
      name => 'INT',
      on_receipt => sub {
         print "SIGINT, will now quit\n";
         $loop->stop;
      },
) );

$loop->run;

read from stdin, catch that SIGINT, run the loop. it's iconic, it's simple, it eats. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this class is a subclass of IO::Async::Loop, and what it does is use epoll(7) on Linux to do the read-ready and write-ready tests, so you get the whole O(1) high-performance multiplexing situation from Linux's epoll_pwait(2) syscall. no cap. πŸ”₯

the "epoll" Linux subsystem keeps a persistent registration system, meaning better performance can be achieved in programs that are out here juggling a large number of filehandles. each epoll_pwait(2) syscall only has an overhead proportional to the number of ready filehandles, rather than the total number being watched. so like β€” the more you're watching, the more this matters. for more detail, go read the epoll(7) manpage, bestie. πŸ“š

this class uses the epoll_pwait(2) system call, which atomically switches the process's signal mask, performs a wait exactly as epoll_wait(2) would, then switches it back. the way this works means a process can block the signals it cares about, but switch in an empty signal mask during the poll, so it can handle file IO and signals concurrently. it's giving multitasking main character energy, fr fr. ✨


πŸŽ€ CONSTRUCTOR πŸŽ€

new

$loop = IO::Async::Loop::Epoll->new();

this function returns a new instance of a "IO::Async::Loop::Epoll" object. that's it, that's the whole thing. brand new loop, fresh out the box. 🫢


πŸ‘‘ METHODS πŸ‘‘

since this is a subclass of IO::Async::Loop, all of its methods are inherited. except where noted below, all of the class's methods behave identically to "IO::Async::Loop". so like, don't stress, you already know them. πŸ’œ

loop_once

$count = $loop->loop_once( $timeout );

this method calls epoll_pwait(2), and processes the results of that call. it returns the total number of "IO::Async::Notifier" callbacks invoked β€” or "undef" if the underlying epoll_pwait() method returned an error. and if the epoll_pwait() was interrupted by a signal, then 0 is returned instead. three possible outcomes, keep track bestie. 🌈


🌟 SEE ALSO 🌟

  • Linux::Epoll β€” O(1) multiplexing for Linux
  • IO::Async::Loop::Poll β€” use IO::Async with poll(2)

πŸ’Œ AUTHOR πŸ’Œ

Paul Evans <leonerd@leonerd.org.uk> β€” thank you for your service, king. πŸ™‡β€β™€οΈ


and that's the page!! perl v5.40.1, dated 2025-05-17 β€” so this is the version you're reading right now, and she's serving. go write some async code, bestie, you're literally gonna slay. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from