blib/lib/IO/Async/OS/linux.pm

filter: Statementstmt 88.8% 16 / 18 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 85.1% 23 / 27 CC 3 SCAR 7.3
CC
3
Cov
86%
potentially_open_fds
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« blib/lib/IO/Async/Signal.pm ↑ Summary blib/lib/IO/Async/Protocol/LineStream.pm »
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 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 103 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 103 our @ISA = qw( IO::Async::OS::_Base );
12  
13 =head1 NAME
14  
15 C<IO::Async::OS::linux> - operating system abstractions on C<Linux> for L<IO::Async>
16  
17 =head1 DESCRIPTION
18  
19 This module contains OS support code for C<Linux>.
20  
21 See instead L<IO::Async::OS>.
22  
23 =cut
24  
25 # Suggest either Epoll or Ppoll loops first if they are installed
26 103 ▶use constant LOOP_PREFER_CLASSES => qw( Epoll Ppoll );
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ▶ my $class = shift;
Subroutine potentially_open_fds: called CC=3 SCAR=11.4
Pod undocumented
34  
35 29 ▶ opendir my $fd_path, "/proc/$$/fd" or do {
Branch: 1 branch
BranchTrueFalseTotal
opendir my $fd_path, "/proc/${$}/fd" or do { warn "Cannot open /proc/${$}/fd, falling back to generic method - $!"; return $class->SUPER::potentially_open_fds } 0 29 29
36 0 warn "Cannot open /proc/$$/fd, falling back to generic method - $!";
37 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 ▶ my @fd = map { m/^([0-9]+)$/ ? $1 : () } readdir $fd_path;
Branch: 1 branch
BranchTrueFalseTotal
/^([0-9]+)$/u ? : 495 58 553
46 29 closedir $fd_path;
47  
48 29 return @fd;
49 }
50  
51 =head1 AUTHOR
52  
53 Paul Evans <leonerd@leonerd.org.uk>
54  
55 =cut
56  
57 103 0x55AA;
« blib/lib/IO/Async/Signal.pm ↑ Summary blib/lib/IO/Async/Protocol/LineStream.pm »