File Coverage

blib/lib/IO/Async/OS/linux.pm
Criterion Covered Total %
statement 15 17 88.2
branch 3 4 75.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 22 26 84.6


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-2015 -- leonerd@leonerd.org.uk
5              
6             package IO::Async::OS::linux;
7              
8 103     103   853 use strict;
  103         211  
  103         3412  
9 103     103   554 use warnings;
  103         248  
  103         6656  
10              
11             our $VERSION = '0.801';
12              
13             our @ISA = qw( IO::Async::OS::_Base );
14              
15             =head1 NAME
16              
17             C - operating system abstractions on C for L
18              
19             =head1 DESCRIPTION
20              
21             This module contains OS support code for C.
22              
23             See instead L.
24              
25             =cut
26              
27             # Suggest either Epoll or Ppoll loops first if they are installed
28 103     103   714 use constant LOOP_PREFER_CLASSES => qw( Epoll Ppoll );
  103         211  
  103         23889  
29              
30             # Try to use /proc/pid/fd to get the list of actually-open file descriptors
31             # for our process. Saves a bit of time when running with high ulimit -n /
32             # fileno counts.
33             sub potentially_open_fds
34             {
35 29     29 0 312 my $class = shift;
36              
37 29 50       6148 opendir my $fd_path, "/proc/$$/fd" or do {
38 0         0 warn "Cannot open /proc/$$/fd, falling back to generic method - $!";
39 0         0 return $class->SUPER::potentially_open_fds
40             };
41              
42             # Skip ., .., our directory handle itself and any other cruft
43             # except fileno() isn't available for the handle so we'll
44             # end up with that in the output anyway. As long as we're
45             # called just before the relevant close() loop, this
46             # should be harmless enough.
47 29 100       2136 my @fd = map { m/^([0-9]+)$/ ? $1 : () } readdir $fd_path;
  408         3359  
48 29         751 closedir $fd_path;
49              
50 29         725 return @fd;
51             }
52              
53             =head1 AUTHOR
54              
55             Paul Evans
56              
57             =cut
58              
59             0x55AA;