File Coverage

blib/lib/IO/Async/OS/linux.pm
Criterion Covered Total %
statement 14 16 87.5
branch 3 4 75.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 21 25 84.0


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2014-2024 -- leonerd@leonerd.org.uk
5              
6             package IO::Async::OS::linux 0.805;
7              
8 103     103   1438 use v5.14;
  103         381  
9 103     103   568 use warnings;
  103         189  
  103         10003  
10              
11             our @ISA = qw( IO::Async::OS::_Base );
12              
13             =head1 NAME
14              
15             C - operating system abstractions on C for L
16              
17             =head1 DESCRIPTION
18              
19             This module contains OS support code for C.
20              
21             See instead L.
22              
23             =cut
24              
25             # Suggest either Epoll or Ppoll loops first if they are installed
26 103     103   609 use constant LOOP_PREFER_CLASSES => qw( Epoll Ppoll );
  103         226  
  103         28212  
27              
28             # Try to use /proc/pid/fd to get the list of actually-open file descriptors
29             # for our process. Saves a bit of time when running with high ulimit -n /
30             # fileno counts.
31             sub potentially_open_fds
32             {
33 29     29 0 300 my $class = shift;
34              
35 29 50       5751 opendir my $fd_path, "/proc/$$/fd" or do {
36 0         0 warn "Cannot open /proc/$$/fd, falling back to generic method - $!";
37 0         0 return $class->SUPER::potentially_open_fds
38             };
39              
40             # Skip ., .., our directory handle itself and any other cruft
41             # except fileno() isn't available for the handle so we'll
42             # end up with that in the output anyway. As long as we're
43             # called just before the relevant close() loop, this
44             # should be harmless enough.
45 29 100       5267 my @fd = map { m/^([0-9]+)$/ ? $1 : () } readdir $fd_path;
  495         4399  
46 29         692 closedir $fd_path;
47              
48 29         831 return @fd;
49             }
50              
51             =head1 AUTHOR
52              
53             Paul Evans
54              
55             =cut
56              
57             0x55AA;