IOMux/Net/TCP.pm

filter: Statementstmt 39.6% 23 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 53.8% 7 / 13 Podpod 83.3% 5 / 6 totaltotal 29.6% 35 / 118 CC 15 SCAR 31.0
CC
15
Cov
26%
shutdown
56.0
init
20.0
muxOutbufferEmpty
20.0
CRAP 22.2
« IOMux/Select.pm ↑ Summary IOMux/IPC.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::Net::TCP;
10 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = '1.01';
12  
13 1 ▶use base 'IOMux::Handler::Read', 'IOMux::Handler::Write';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Log::Report 'iomux';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Socket 'SOCK_STREAM';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 sub init($)
24 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=4 SCAR=30.0
Pod undocumented
25  
26 0 ▶ $args->{Proto} ||= 'tcp';
Condition0%0/2
$args->{"Proto"} ||= "tcp"
l!l
00
MC/DC0%0/1
$args->{"Proto"} ||= "tcp"
$args->{"Proto"}
Truth table0%0/2
A
A= $args->{"Proto"}
Aresult
11
00
27 my $socket = $args->{fh}
28 0 ▶ = (delete $args->{socket}) || $self->extractSocket($args);
Condition0%0/3
delete $args->{'socket'} || $self->extractSocket($args)
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $args->{'socket'} || $self->extractSocket($args)
delete $args->{'socket'} $self->extractSocket($args)
Truth table0%0/3
A || B
A= delete $args->{'socket'}B= $self->extractSocket($args)
ABresult
1X1
011
000
29  
30 0 ▶ $args->{name} ||= "tcp ".$socket->peerhost.':'.$socket->peerport;
Condition0%0/2
$args->{"name"} ||= 'tcp ' . $socket->peerhost . ':' . $socket->peerport
l!l
00
MC/DC0%0/1
$args->{"name"} ||= 'tcp ' . $socket->peerhost . ':' . $socket->peerport
$args->{"name"}
Truth table0%0/2
A
A= $args->{"name"}
Aresult
11
00
31  
32 0 $self->IOMux::Handler::Read::init($args);
33 0 $self->IOMux::Handler::Write::init($args);
34  
35 0 $self;
36 }
37  
38 #-------------------
39  
40 0 ▶sub socket() {shift->fh}
Subroutine socket: not called CC=1 SCAR=6.9
Pod documented
41  
42 #-------------------
43  
44 sub shutdown($)
45 0 ▶{ my($self, $which) = @_;
Subroutine shutdown: not called CC=7 SCAR=40.3
Pod documented
46 0 my $socket = $self->socket;
47 0 my $mux = $self->mux;
48  
49 0 ▶ if($which!=1)
Branch: 1 branch
BranchTrueFalseTotal
if ($which != 1) 0 0 0
50 { # Shutdown for reading. We can do this now.
51 0 $socket->shutdown(0);
52 0 $self->{IMNT_shutread} = 1;
53 # The muxEOF hook must be run from the main loop to consume
54 # the rest of the inbuffer if there is anything left.
55 # It will also remove $fh from _readers.
56 0 $self->fdset(0, 1, 0, 0);
57 }
58 0 ▶ if($which!=0)
Branch: 1 branch
BranchTrueFalseTotal
if ($which != 0) 0 0 0
59 { # Shutdown for writing. Only do this now if there is no pending data.
60 0 $self->{IMNT_shutwrite} = 1;
61 0 ▶ unless($self->muxOutputWaiting)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->muxOutputWaiting) 0 0 0
62 0 { $socket->shutdown(1);
63 0 $self->fdset(0, 0, 1, 0);
64 }
65 }
66  
67 $self->close
68 if $self->{IMNT_shutread}
69 0 ▶ && $self->{IMNT_shutwrite} && !$self->muxOutputWaiting;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"IMNT_shutread"} and $self->{"IMNT_shutwrite"} and not $self->muxOutputWaiting 0 0 0
Condition0%0/6
$self->{"IMNT_shutread"} and $self->{"IMNT_shutwrite"} and not $self->muxOutputWaiting
!ll&&!rl&&r
000
$self->{"IMNT_shutread"} and $self->{"IMNT_shutwrite"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"IMNT_shutread"} and $self->{"IMNT_shutwrite"} and not $self->muxOutputWaiting
$self->{"IMNT_shutread"} $self->{"IMNT_shutwrite"} not $self->muxOutputWaiting
Truth table0%0/4
A and B and not(C)
A= $self->{"IMNT_shutread"}B= $self->{"IMNT_shutwrite"}C= not $self->muxOutputWaiting
ABCresult
0XX0
10X0
1100
1111
70 }
71  
72 sub close()
73 0 ▶{ my $self = shift;
Subroutine close: not called CC=3 SCAR=24.8
Pod documented
74  
75 warning __x"closing {name} with read buffer", name => $self->name
76 0 ▶ if length $self->{ICMT_inbuf};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"ICMT_inbuf"} 0 0 0
77  
78 warning __x"closing {name} with write buffer", name => $self->name
79 0 ▶ if $self->{ICMT_outbuf};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ICMT_outbuf"} 0 0 0
80  
81 0 $self->socket->close;
82 0 $self->SUPER::close;
83 }
84  
85 #-------------------------
86  
87 sub muxInit($)
88 0 ▶{ my ($self, $mux) = @_;
Subroutine muxInit: not called CC=1 SCAR=6.9
Pod documented
89 0 $self->SUPER::muxInit($mux);
90  
91 # we will not listen for write until we have something to write
92 0 $self->fdset(1, 1, 0, 1);
93 }
94  
95 sub muxOutbufferEmpty()
96 0 ▶{ my $self = shift;
Subroutine muxOutbufferEmpty: not called CC=4 SCAR=30.0
Pod documented
97 0 $self->SUPER::muxOutbufferEmpty;
98  
99 0 ▶ if($self->{IMNT_shutwrite} && !$self->muxOutputWaiting)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"IMNT_shutwrite"} and not $self->muxOutputWaiting) 0 0 0
Condition0%0/3
$self->{"IMNT_shutwrite"} and not $self->muxOutputWaiting
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"IMNT_shutwrite"} and not $self->muxOutputWaiting
$self->{"IMNT_shutwrite"} not $self->muxOutputWaiting
Truth table0%0/3
A and not(B)
A= $self->{"IMNT_shutwrite"}B= not $self->muxOutputWaiting
ABresult
0X0
100
111
100 0 { $self->socket->shutdown(1);
101 0 $self->fdset(0, 0, 1, 0);
102 0 ▶ $self->close if $self->{IMNT_shutread};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"IMNT_shutread"} 0 0 0
103 }
104 }
105  
106  
107 1 1;
« IOMux/Select.pm ↑ Summary IOMux/IPC.pm »