blib/lib/Net/TCP.pm

filter: Statementstmt 47.1% 33 / 70 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 60.0% 9 / 15 Podpod 33.3% 1 / 3 totaltotal 32.3% 43 / 133 CC 17 SCAR 36.5
CC
17
Cov
31%
new
90.9
_addrinfo
42.0
_debug
6.8
CRAP 38.6
« blib/lib/Net/TCP/Server.pm ↑ Summary blib/lib/Net/Gen.pm »
1 # Copyright 1995,2002 Spider Boardman.
2 # All rights reserved.
3 #
4 # Automatic licensing for this software is available. This software
5 # can be copied and used under the terms of the GNU Public License,
6 # version 1 or (at your option) any later version, or under the
7 # terms of the Artistic license. Both of these can be found with
8 # the Perl distribution, which this software is intended to augment.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13  
14 # rcsid: "@(#) $Id: TCP.dat,v 1.25 2002/03/30 10:11:53 spider Exp $"
15  
16 package Net::TCP;
17 1 ▶use 5.004_04; # new minimum Perl version for this package
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 #use Carp;
21 0 ▶sub carp { require Carp; goto &Carp::carp; }
Subroutine carp: not called CC=1 SCAR=6.9
Pod undocumented
22 0 ▶sub croak { require Carp; goto &Carp::croak; }
Subroutine croak: not called CC=1 SCAR=6.9
Pod undocumented
23 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS *AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 $VERSION = '1.0';
27 1 eval "sub Version () { __PACKAGE__ . ' v$VERSION' }";
28 }
29  
30 #use AutoLoader; # disable this until we have autoloadable subs again
31 #use Exporter (); # we inherit what we need here from Net::Gen
32 1 ▶use Net::Inet 1.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Net::Gen 1.0 ':sockvals', ':families';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 @ISA = 'Net::Inet';
37 1 *AUTOLOAD = \$Net::Gen::AUTOLOAD;
38  
39 # Items to export into callers namespace by default
40 # (move infrequently used names to @EXPORT_OK below)
41 1 @EXPORT = qw(
42 );
43  
44 # Other items we are prepared to export if requested
45 1 @EXPORT_OK = qw(
46 TCPOPT_EOL
47 TCPOPT_MAXSEG
48 TCPOPT_NOP
49 TCPOPT_WINDOW
50 TCP_MAXSEG
51 TCP_MAXWIN
52 TCP_MAX_WINSHIFT
53 TCP_MSS
54 TCP_NODELAY
55 TCP_RPTR2RXT
56 TH_ACK
57 TH_FIN
58 TH_PUSH
59 TH_RST
60 TH_SYN
61 TH_URG
62 );
63  
64 1 %EXPORT_TAGS = (
65 sockopts => [qw(TCP_NODELAY TCP_MAXSEG TCP_RPTR2RXT)],
66 tcpoptions => [qw(TCPOPT_EOL TCPOPT_MAXSEG TCPOPT_NOP
67 TCPOPT_WINDOW)],
68 protocolvalues => [qw(TCP_MAXWIN TCP_MAX_WINSHIFT TCP_MSS
69 TH_ACK TH_FIN TH_PUSH TH_RST TH_SYN TH_URG)],
70 ALL => [@EXPORT, @EXPORT_OK],
71 );
72 }
73  
74 ;# sub AUTOLOAD inherited from Net::Gen (via Net::Inet)
75  
76 ;# However, since 5.003_96 will make simple subroutines not inherit AUTOLOAD...
77 sub AUTOLOAD
78 0 ▶{
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
79 #$Net::Gen::AUTOLOAD = $AUTOLOAD;
80 0 goto &Net::Gen::AUTOLOAD;
81 }
82  
83  
84 # Preloaded methods go here. Autoload methods go after __END__, and are
85 # processed by the autosplit program.
86  
87  
88 1 my %sockopts;
89  
90 1 %sockopts = (
91 # known TCP socket options
92 # simple booleans first
93  
94 'TCP_NODELAY' => ['i'],
95  
96 # simple integer options
97  
98 'TCP_MAXSEG' => ['i'],
99 'TCP_RPTR2RXT' => ['i'],
100  
101 # structured options
102  
103 # out of known TCP options
104 );
105  
106 1 __PACKAGE__->initsockopts( IPPROTO_TCP, \%sockopts );
107  
108 1 my $debug = 0;
109  
110 #& _debug($this, [$newval]) : oldval
111 sub _debug
112 0 ▶{
Subroutine _debug: not called CC=3 SCAR=19.2
113 1 ▶ use attrs qw(locked);
Subroutine BEGIN: called CC=1 SCAR=0.0
114 0 my ($this,$newval) = @_;
115 0 ▶ return $this->debug($newval) if ref $this;
Branch: 1 branch
BranchTrueFalseTotal
if ref $this 0 0 0
116 0 my $prev = $debug;
117 0 ▶ $debug = 0+$newval if defined $newval;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newval 0 0 0
118 0 $prev;
119 }
120  
121 1 my %Sopts; # do a full register_options only once
122  
123 sub new
124 0 ▶{
Subroutine new: not called CC=10 SCAR=45.1
Pod documented
125 1 ▶ use attrs qw(locked);
Subroutine BEGIN: called CC=1 SCAR=0.0
126 0 my $whoami = $_[0]->_trace(\@_,1);
127 0 my($class,@args) = @_;
128 0 my $self = $class->SUPER::new(@args);
129 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
130 0 ▶ ($self || $class)->_trace(\@_,2,", self" .
Branch: 1 branch
BranchTrueFalseTotal
defined $self ? : 0 0 0
Condition0%0/3
$self || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$self || $class
$self $class
Truth table0%0/3
A || B
A= $selfB= $class
ABresult
1X1
011
000
131 (defined $self ? "=$self" : " undefined") .
132 " after sub-new");
133 0 ▶ if ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 0 0 0
134 ;# no new keys for TCP?
135 # register our socket options
136 0 ▶ if (%Sopts) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Sopts) { } 0 0 0
137 0 $ {*$self}{Sockopts} = { %Sopts } ;
138 }
139 else {
140 0 $self->register_options('IPPROTO_TCP', IPPROTO_TCP(), \%sockopts);
141 0 %Sopts = %{ $ {*$self}{Sockopts} } ;
142 }
143 # set our expected parameters
144 0 $self->setparams({IPproto => 'tcp',
145 type => SOCK_STREAM,
146 proto => IPPROTO_TCP},-1);
147 0 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 0 0
148 0 ▶ unless ($self->init(@args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->init(@args)) 0 0 0
149 0 local $!; # protect returned errno value
150 0 undef $self; # against excess closes in perl core
151 0 undef $self; # another statement needed for sequencing
152 }
153 }
154 }
155 0 ▶ ($self || $class)->_trace(0,1," returning " .
Branch: 1 branch
BranchTrueFalseTotal
defined $self ? : 0 0 0
Condition0%0/3
$self || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
$self || $class
$self $class
Truth table0%0/3
A || B
A= $selfB= $class
ABresult
1X1
011
000
156 (defined $self ? "self=$self" : "undef"));
157 0 $self;
158 }
159  
160 #& _addrinfo($this, $sockaddr, [numeric_only]) : @list
161 sub _addrinfo
162 0 ▶{
Subroutine _addrinfo: not called CC=6 SCAR=37.4
163 0 my($this,@args,@r) = @_;
164 0 @r = $this->SUPER::_addrinfo(@args);
165 0 ▶ unless (!@r or $args[1] or ref($this) or $r[2] ne $r[3]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not @r or $args[1] or ref $this or $r[2] ne $r[3]) 0 0 0
Condition0%0/9
not @r or $args[1] or ref $this or $r[2] ne $r[3]
l!l&&r!l&&!r
000
not @r or $args[1] or ref $this
l!l&&r!l&&!r
000
not @r or $args[1]
l!l&&r!l&&!r
000
MC/DC0%0/4
not @r or $args[1] or ref $this or $r[2] ne $r[3]
not @r $args[1] ref $this $r[2] ne $r[3]
Truth table0%0/5
not(A) or B or C or D
A= not @rB= $args[1]C= ref $thisD= $r[2] ne $r[3]
ABCDresult
1XXX1
01XX1
001X1
00011
00000
166 0 $this = getservbyport(htons($r[3]), 'tcp');
167 0 ▶ $r[2] = $this if defined $this;
Branch: 1 branch
BranchTrueFalseTotal
if defined $this 0 0 0
168 }
169 0 @r;
170 }
171  
172  
173 1 1;
174  
175 # autoloaded methods go after the END token (& pod) below
176  
177 __END__
« blib/lib/Net/TCP/Server.pm ↑ Summary blib/lib/Net/Gen.pm »