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
|
101
|
|
|
101
|
|
747
|
use strict; |
|
101
|
|
|
|
|
224
|
|
|
101
|
|
|
|
|
3541
|
|
9
|
101
|
|
|
101
|
|
543
|
use warnings; |
|
101
|
|
|
|
|
313
|
|
|
101
|
|
|
|
|
6671
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.79'; |
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
|
101
|
|
|
101
|
|
630
|
use constant LOOP_PREFER_CLASSES => qw( Epoll Ppoll ); |
|
101
|
|
|
|
|
181
|
|
|
101
|
|
|
|
|
24084
|
|
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
|
286
|
my $class = shift; |
36
|
|
|
|
|
|
|
|
37
|
29
|
50
|
|
|
|
6387
|
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
|
|
|
|
2705
|
my @fd = map { m/^([0-9]+)$/ ? $1 : () } readdir $fd_path; |
|
408
|
|
|
|
|
3444
|
|
48
|
29
|
|
|
|
|
698
|
closedir $fd_path; |
49
|
|
|
|
|
|
|
|
50
|
29
|
|
|
|
|
566
|
return @fd; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Paul Evans |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
0x55AA; |