IOMux/Poll.pm

filter: Statementstmt 92.5% 62 / 67 Branchbran 56.6% 17 / 30 Conditioncond 37.5% 3 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 92.8% 13 / 14 Podpod 50.0% 2 / 4 totaltotal 76.5% 98 / 128 CC 20 SCAR 18.5
CC
20
Cov
78%
fdset
10.2
one_go
9.9
_ready
6.4
CRAP 6.3
« IOMux/File/Write.pm ↑ Summary IOMux/Bundle.pm »
1 # Copyrights 2011-2020 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution IOMux. Meta-POD processed with OODoc
6 # into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package IOMux::Poll;
10 8 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 $VERSION = '1.01';
12  
13 8 ▶use base 'IOMux';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 8 ▶use Log::Report 'iomux';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 8 ▶use List::Util 'min';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 8 ▶use POSIX 'errno_h';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 8 ▶use IO::Poll;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 8 $SIG{PIPE} = 'IGNORE'; # pipes are handled in select
26  
27  
28 8 my $poll;
29 sub init($)
30 7 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=2 SCAR=7.4
Pod undocumented
31 7 $self->SUPER::init($args);
32 7 ▶ $poll ||= IO::Poll->new;
Condition33%1/3
$poll ||= "IO::Poll"->new
l!l&&r!l&&!r
070
MC/DC0%0/2
$poll ||= "IO::Poll"->new
$poll "IO::Poll"->new
Truth table33%1/3
A ||= B
A= $pollB= "IO::Poll"->new
ABresult
1X1
011
000
33 7 $self;
34 }
35  
36 #-------------
37  
38 0 ▶sub poller {$poll}
Subroutine poller: not called CC=1 SCAR=6.9
Pod documented
39  
40 #-------------
41  
42 sub fdset($$$$$)
43 32 ▶{ my ($self, $fileno, $state, $r, $w, $e) = @_;
Subroutine fdset: called CC=10 SCAR=23.3
Pod documented
44 32 ▶ my $conn = $self->handler($fileno) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $conn = $self->handler($fileno) or return 19 13 32
45 19 my $fh = $conn->fh;
46 19 ▶ my $mask = $poll->mask($fh) || 0;
Condition100%2/2
$poll->mask($fh) || 0
l!l
613
MC/DC100%1/1
$poll->mask($fh) || 0
$poll->mask($fh)
Truth table100%2/2
A
A= $poll->mask($fh)
Aresult
11
00
47 19 ▶ if($state==0)
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 0) { } 13 6 19
48 13 ▶ { $mask &= ~POLLIN if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 6 7 13
49 13 ▶ $mask &= ~POLLOUT if $w;
Branch: 1 branch
BranchTrueFalseTotal
if $w 7 6 13
50 13 ▶ $mask &= ~POLLERR if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 13 13
51 }
52 else
53 6 ▶ { $mask |= POLLIN if $r;
Branch: 1 branch
BranchTrueFalseTotal
if $r 6 0 6
54 6 ▶ $mask |= POLLOUT if $w;
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 6 6
55 6 ▶ $mask |= POLLERR if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 6 6
56 }
57 19 $poll->mask($fh, $mask);
58 }
59  
60 sub one_go($$)
61 12 ▶{ my ($self, $wait, $heartbeat) = @_;
Subroutine one_go: called CC=6 SCAR=23.0
Pod undocumented
62  
63 12 my $numready = $poll->poll($wait);
64  
65 12 ▶ $heartbeat->($self, $numready, undef)
Branch: 1 branch
BranchTrueFalseTotal
if $heartbeat 0 12 12
66 if $heartbeat;
67  
68 12 ▶ if($numready < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($numready < 0) 0 12 12
69 0 ▶ { return if $! == EINTR || $! == EAGAIN;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 4 or $! == 11 0 0 0
Condition0%0/3
$! == 4 or $! == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$! == 4 or $! == 11
$! == 4 $! == 11
Truth table0%0/3
A or B
A= $! == 4B= $! == 11
ABresult
1X1
011
000
70 0 alert "leaving loop";
71 0 return 0;
72 }
73  
74 $numready
75 12 ▶ or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$numready or return 1 12 0 12
76
77 12 $self->_ready(muxReadFlagged => POLLIN|POLLHUP);
78 12 $self->_ready(muxWriteFlagged => POLLOUT);
79 12 $self->_ready(muxExceptFlagged => POLLERR);
80  
81 12 1; # success
82 }
83  
84 # It would be nice to have an algorithm which is better than O(n)
85 sub _ready($$)
86 36 ▶{ my ($self, $call, $mask) = @_;
Subroutine _ready: called CC=5 SCAR=18.6
87 36 my $handlers = $self->_handlers;
88 36 foreach my $fh ($poll->handles($mask))
89 12 ▶ { my $fileno = $fh->fileno or next; # close filehandle
Branch: 1 branch
BranchTrueFalseTotal
my $fileno = $fh->fileno or next 12 0 12
90 12 ▶ if(my $conn = $handlers->{$fileno})
Branch: 1 branch
BranchTrueFalseTotal
if (my $conn = $handlers->{$fileno}) { } 12 0 12
91 { # filehandle flagged
92 12 $conn->$call($fileno);
93 }
94 else
95 { # Handler administration error, but when write and error it may
96 # be caused by read errors.
97 0 ▶ alert "connection for ".$fh->fileno." not registered in $call"
Branch: 1 branch
BranchTrueFalseTotal
if $call eq "muxReadFlagged" 0 0 0
98 if $call eq 'muxReadFlagged';
99 }
100 }
101 }
102  
103 8 1;
104  
105 __END__
« IOMux/File/Write.pm ↑ Summary IOMux/Bundle.pm »