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
6package IO::Async::OS::linux;
7
8use strict;
9use warnings;
10
11our $VERSION = '0.800';
12
13our @ISA = qw( IO::Async::OS::_Base );
14
15=head1 NAME
16
17C<IO::Async::OS::linux> - operating system abstractions on C<Linux> for L<IO::Async>
18
19=head1 DESCRIPTION
20
21This module contains OS support code for C<Linux>.
22
23See instead L<IO::Async::OS>.
24
25=cut
26
27# Suggest either Epoll or Ppoll loops first if they are installed
28use constant LOOP_PREFER_CLASSES => qw( Epoll Ppoll );
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.
33sub potentially_open_fds
34{
35   my $class = shift;
36
37   opendir my $fd_path, "/proc/$$/fd" or do {
38      warn "Cannot open /proc/$$/fd, falling back to generic method - $!";
39      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   my @fd = map { m/^([0-9]+)$/ ? $1 : () } readdir $fd_path;
48   closedir $fd_path;
49
50   return @fd;
51}
52
53=head1 AUTHOR
54
55Paul Evans <leonerd@leonerd.org.uk>
56
57=cut
58
590x55AA;
60