IOMux/Service/TCP.pm

filter: Statementstmt 47.9% 23 / 48 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 58.3% 7 / 12 Podpod 80.0% 4 / 5 totaltotal 36.9% 34 / 92 CC 10 SCAR 33.9
CC
10
Cov
34%
init
72.0
muxReadFlagged
12.0
clientType
2.0
CRAP 29.8
« IOMux/Handler.pm ↑ Summary IOMux/Handler/Write.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::Service::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::Service';
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 IOMux::Net::TCP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Socket 'SOCK_STREAM';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 sub init($)
25 0 ▶{ my ($self, $args) = @_;
Subroutine init: not called CC=8 SCAR=42.8
Pod undocumented
26  
27 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
28 0 ▶ my $socket = 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 0 ▶ $socket->socktype eq SOCK_STREAM
Branch: 1 branch
BranchTrueFalseTotal
$socket->socktype eq 1 or &error(&__x("{pkg} needs STREAM protocol socket", "pkg", ref $self)) 0 0 0
30 or error __x"{pkg} needs STREAM protocol socket", pkg => ref $self;
31 0 $args->{fh} = $socket;
32  
33 0 my $sockaddr = $socket->sockhost.':'.$socket->sockport;
34 0 ▶ $args->{name} ||= "listen tcp $sockaddr";
Condition0%0/2
$args->{"name"} ||= "listen tcp $sockaddr"
l!l
00
MC/DC0%0/1
$args->{"name"} ||= "listen tcp $sockaddr"
$args->{"name"}
Truth table0%0/2
A
A= $args->{"name"}
Aresult
11
00
35  
36 0 $self->SUPER::init($args);
37  
38 my $ct = $self->{IMST_conn_type} = $args->{conn_type}
39 0 ▶ or error __x"a conn_type for incoming request is need by {name}"
Branch: 1 branch
BranchTrueFalseTotal
my $ct = $self->{"IMST_conn_type"} = $args->{"conn_type"} or &error(&__x("a conn_type for incoming request is need by {name}", "name", $self->name)) 0 0 0
40 , name => $self->name;
41  
42 0 ▶ $self->{IMST_conn_opts} = $args->{conn_opts} || [];
Condition0%0/2
$args->{'conn_opts'} || []
l!l
00
MC/DC0%0/1
$args->{'conn_opts'} || []
$args->{'conn_opts'}
Truth table0%0/2
A
A= $args->{'conn_opts'}
Aresult
11
00
43 0 ▶ $self->{IMST_hostname} = $args->{hostname} || $sockaddr;
Condition0%0/3
$args->{'hostname'} || $sockaddr
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{'hostname'} || $sockaddr
$args->{'hostname'} $sockaddr
Truth table0%0/3
A || B
A= $args->{'hostname'}B= $sockaddr
ABresult
1X1
011
000
44 0 $self;
45 }
46  
47 #------------------------
48  
49 0 ▶sub clientType() {shift->{IMST_conn_type}}
Subroutine clientType: not called CC=1 SCAR=6.9
Pod documented
50 0 ▶sub socket() {shift->fh}
Subroutine socket: not called CC=1 SCAR=6.9
Pod documented
51 0 ▶sub hostname() {shift->{IMST_hostname}}
Subroutine hostname: not called CC=1 SCAR=6.9
Pod documented
52  
53 #-------------------------
54  
55 # The read flag is set on the socket, which means that a new connection
56 # attempt is made.
57  
58  
59 sub muxReadFlagged()
60 0 ▶{ my $self = shift;
Subroutine muxReadFlagged: not called CC=3 SCAR=24.8
Pod documented
61  
62 0 my $client = $self->socket->accept;
63 0 ▶ unless($client)
Branch: 1 branch
BranchTrueFalseTotal
unless ($client) 0 0 0
64 0 { alert __x"accept for socket {name} failed", name => $self->name;
65 0 return;
66 }
67  
68 # create an object which handles this connection
69 0 my $ct = $self->clientType;
70 0 my $opts = $self->{IMST_conn_opts};
71 0 ▶ my $handler = ref $ct eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $ct eq 'CODE' ? : 0 0 0
72 ? $ct-> (socket => $client, Proto => 'tcp', @$opts)
73 : $ct->new(socket => $client, Proto => 'tcp', @$opts);
74  
75 # add the new socket to the mux, to be watched
76 0 $self->mux->add($handler);
77  
78 0 $self->muxConnection($client);
79 }
80  
81 1 1;
« IOMux/Handler.pm ↑ Summary IOMux/Handler/Write.pm »