| 1 |
NAME |
| 2 |
|
| 3 |
IO::Async::Loop::Epoll - use IO::Async with epoll on Linux |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
|
| 7 |
use IO::Async::Loop::Epoll; |
| 8 |
|
| 9 |
use IO::Async::Stream; |
| 10 |
use IO::Async::Signal; |
| 11 |
|
| 12 |
my $loop = IO::Async::Loop::Epoll->new; |
| 13 |
|
| 14 |
$loop->add( IO::Async::Stream->new( |
| 15 |
read_handle => \*STDIN, |
| 16 |
on_read => sub { |
| 17 |
my ( $self, $buffref ) = @_; |
| 18 |
while( $$buffref =~ s/^(.*)\r?\n// ) { |
| 19 |
print "You said: $1\n"; |
| 20 |
} |
| 21 |
}, |
| 22 |
) ); |
| 23 |
|
| 24 |
$loop->add( IO::Async::Signal->new( |
| 25 |
name => 'INT', |
| 26 |
on_receipt => sub { |
| 27 |
print "SIGINT, will now quit\n"; |
| 28 |
$loop->stop; |
| 29 |
}, |
| 30 |
) ); |
| 31 |
|
| 32 |
$loop->run; |
| 33 |
|
| 34 |
DESCRIPTION |
| 35 |
|
| 36 |
This subclass of IO::Async::Loop uses epoll(7) on Linux to perform |
| 37 |
read-ready and write-ready tests so that the O(1) high-performance |
| 38 |
multiplexing of Linux's epoll_pwait(2) syscall can be used. |
| 39 |
|
| 40 |
The epoll Linux subsystem uses a persistent registration system, |
| 41 |
meaning that better performance can be achieved in programs using a |
| 42 |
large number of filehandles. Each epoll_pwait(2) syscall only has an |
| 43 |
overhead proportional to the number of ready filehandles, rather than |
| 44 |
the total number being watched. For more detail, see the epoll(7) |
| 45 |
manpage. |
| 46 |
|
| 47 |
This class uses the epoll_pwait(2) system call, which atomically |
| 48 |
switches the process's signal mask, performs a wait exactly as |
| 49 |
epoll_wait(2) would, then switches it back. This allows a process to |
| 50 |
block the signals it cares about, but switch in an empty signal mask |
| 51 |
during the poll, allowing it to handle file IO and signals |
| 52 |
concurrently. |
| 53 |
|
| 54 |
CONSTRUCTOR |
| 55 |
|
| 56 |
new |
| 57 |
|
| 58 |
$loop = IO::Async::Loop::Epoll->new(); |
| 59 |
|
| 60 |
This function returns a new instance of a IO::Async::Loop::Epoll |
| 61 |
object. |
| 62 |
|
| 63 |
METHODS |
| 64 |
|
| 65 |
As this is a subclass of IO::Async::Loop, all of its methods are |
| 66 |
inherited. Expect where noted below, all of the class's methods behave |
| 67 |
identically to IO::Async::Loop. |
| 68 |
|
| 69 |
loop_once |
| 70 |
|
| 71 |
$count = $loop->loop_once( $timeout ); |
| 72 |
|
| 73 |
This method calls epoll_pwait(2), and processes the results of that |
| 74 |
call. It returns the total number of IO::Async::Notifier callbacks |
| 75 |
invoked, or undef if the underlying epoll_pwait() method returned an |
| 76 |
error. If the epoll_pwait() was interrupted by a signal, then 0 is |
| 77 |
returned instead. |
| 78 |
|
| 79 |
SEE ALSO |
| 80 |
|
| 81 |
* Linux::Epoll - O(1) multiplexing for Linux |
| 82 |
|
| 83 |
* IO::Async::Loop::Poll - use IO::Async with poll(2) |
| 84 |
|
| 85 |
AUTHOR |
| 86 |
|
| 87 |
Paul Evans <[email protected]> |
| 88 |
|