blib/lib/IO/Socket.pm

filter: Statementstmt 78.6% 169 / 215 Branchbran 52.2% 70 / 134 Conditioncond 35.6% 26 / 73 MC/DCmcdc 9.0% 4 / 44 Subroutinesub 84.8% 28 / 33 Podpod 84.0% 21 / 25 totaltotal 60.6% 318 / 524 CC 92 SCAR 29.3
CC
92
Cov
63%
connect
63.2
blocking
36.0
timeout
30.0
CRAP 18.6
« blib/lib/IO/Pipe.pm ↑ Summary blib/lib/IO/Select.pm »
1  
2 # IO::Socket.pm
3 #
4 # Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 package IO::Socket;
9  
10 18 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 18 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use Socket 1.3;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use Errno;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # legacy
20  
21 18 require IO::Socket::INET;
22 18 ▶require IO::Socket::UNIX if ($^O ne 'epoc' && $^O ne 'symbian');
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "epoc" and $^O ne "symbian" 18 0 18
Condition33%1/3
$^O ne "epoc" and $^O ne "symbian"
!ll&&!rl&&r
0018
MC/DC0%0/2
$^O ne "epoc" and $^O ne "symbian"
$^O ne "epoc" $^O ne "symbian"
Truth table33%1/3
A and B
A= $^O ne "epoc"B= $^O ne "symbian"
ABresult
0X0
100
111
23  
24 18 our @ISA = qw(IO::Handle);
25  
26 18 our $VERSION = "1.55";
27  
28 18 our @EXPORT_OK = qw(sockatmark);
29  
30 18 our $errstr;
31  
32 57 ▶sub import {
Subroutine import: called CC=3 SCAR=11.8
33 57 my $pkg = shift;
34 57 ▶ if (@_ && $_[0] eq 'sockatmark') { # not very extensible but for now, fast
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0] eq 'sockatmark') { } 0 57 57
Condition66%2/3
@_ and $_[0] eq "sockatmark"
!ll&&!rl&&r
5610
MC/DC0%0/2
@_ and $_[0] eq "sockatmark"
@_ $_[0] eq "sockatmark"
Truth table66%2/3
A and B
A= @_B= $_[0] eq "sockatmark"
ABresult
0X0
100
111
35 0 Exporter::export_to_level('IO::Socket', 1, $pkg, 'sockatmark');
36 } else {
37 57 my $callpkg = caller;
38 57 Exporter::export 'Socket', $callpkg, @_;
39 }
40 }
41  
42 63 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
43 63 my($class,%arg) = @_;
44 63 my $sock = $class->SUPER::new();
45  
46 63 $sock->autoflush(1);
47  
48 63 ${*$sock}{'io_socket_timeout'} = delete $arg{Timeout};
49  
50 63 ▶ return scalar(%arg) ? $sock->configure(\%arg)
Branch: 1 branch
BranchTrueFalseTotal
scalar %arg ? : 42 21 63
51 : $sock;
52 }
53  
54 18 my @domain2pkg;
55  
56 36 ▶sub register_domain {
Subroutine register_domain: called CC=1 SCAR=0.0
Pod undocumented
57 36 my($p,$d) = @_;
58 36 $domain2pkg[$d] = $p;
59 }
60  
61 4 ▶sub configure {
Subroutine configure: called CC=4 SCAR=14.3
Pod undocumented
62 4 my($sock,$arg) = @_;
63 4 my $domain = delete $arg->{Domain};
64  
65 4 ▶ croak 'IO::Socket: Cannot configure a generic socket'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain 0 4 4
66 unless defined $domain;
67  
68 4 ▶ croak "IO::Socket: Unsupported socket domain"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain2pkg[$domain] 0 4 4
69 unless defined $domain2pkg[$domain];
70  
71 4 ▶ croak "IO::Socket: Cannot configure socket in domain '$domain'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sock eq "IO::Socket" 0 4 4
72 unless ref($sock) eq "IO::Socket";
73  
74 4 bless($sock, $domain2pkg[$domain]);
75 4 $sock->configure($arg);
76 }
77  
78 44 ▶sub socket {
Subroutine socket: called CC=4 SCAR=13.9
Pod documented
79 44 ▶ @_ == 4 or croak 'usage: $sock->socket(DOMAIN, TYPE, PROTOCOL)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("usage: \$sock->socket(DOMAIN, TYPE, PROTOCOL)") 44 0 44
80 44 my($sock,$domain,$type,$protocol) = @_;
81  
82 44 ▶ socket($sock,$domain,$type,$protocol) or
Branch: 1 branch
BranchTrueFalseTotal
CORE::socket $sock, $domain, $type, $protocol or return undef 44 0 44
83 return undef;
84  
85 44 ${*$sock}{'io_socket_domain'} = $domain;
86 44 ${*$sock}{'io_socket_type'} = $type;
87  
88 # "A value of 0 for protocol will let the system select an
89 # appropriate protocol"
90 # so we need to look up what the system selected,
91 # not cache PF_UNSPEC.
92 44 ▶ ${*$sock}{'io_socket_proto'} = $protocol if $protocol;
Branch: 1 branch
BranchTrueFalseTotal
if $protocol 37 7 44
93  
94 44 $sock;
95 }
96  
97 0 ▶sub socketpair {
Subroutine socketpair: not called CC=3 SCAR=24.8
Pod documented
98 0 ▶ @_ == 4 || croak 'usage: IO::Socket->socketpair(DOMAIN, TYPE, PROTOCOL)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("usage: IO::Socket->socketpair(DOMAIN, TYPE, PROTOCOL)") 0 0 0
99 0 my($class,$domain,$type,$protocol) = @_;
100 0 my $sock1 = $class->new();
101 0 my $sock2 = $class->new();
102  
103 0 ▶ socketpair($sock1,$sock2,$domain,$type,$protocol) or
Branch: 1 branch
BranchTrueFalseTotal
CORE::socketpair $sock1, $sock2, $domain, $type, $protocol or return () 0 0 0
104 return ();
105  
106 0 ${*$sock1}{'io_socket_type'} = ${*$sock2}{'io_socket_type'} = $type;
107 0 ${*$sock1}{'io_socket_proto'} = ${*$sock2}{'io_socket_proto'} = $protocol;
108  
109 0 ($sock1,$sock2);
110 }
111  
112 14 ▶sub connect {
Subroutine connect: called CC=22 SCAR=41.5
Pod undocumented
113 14 ▶ @_ == 2 or croak 'usage: $sock->connect(NAME)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$sock->connect(NAME)") 14 0 14
114 14 my $sock = shift;
115 14 my $addr = shift;
116 14 my $timeout = ${*$sock}{'io_socket_timeout'};
117 14 my $err;
118 my $blocking;
119  
120 14 ▶ $blocking = $sock->blocking(0) if $timeout;
Branch: 1 branch
BranchTrueFalseTotal
if $timeout 1 13 14
121 14 ▶ if (!connect($sock, $addr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (CORE::connect $sock, $addr) 2 12 14
122 2 ▶ if (defined $timeout && ($!{EINPROGRESS} || $!{EWOULDBLOCK})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $timeout and $!{'EINPROGRESS'} || $!{'EWOULDBLOCK'}) { } 1 1 2
elsif ($blocking or not $!{'EINPROGRESS'} || $!{'EWOULDBLOCK'}) { } 1 0 1
Condition50%3/6
defined $timeout and $!{"EINPROGRESS"} || $!{"EWOULDBLOCK"}
!ll&&!rl&&r
101
$!{"EINPROGRESS"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
100
MC/DC33%1/3
defined $timeout and $!{"EINPROGRESS"} || $!{"EWOULDBLOCK"}
defined $timeout $!{"EINPROGRESS"} $!{"EWOULDBLOCK"}
Truth table50%2/4
A and B or C
A= defined $timeoutB= $!{"EINPROGRESS"}C= $!{"EWOULDBLOCK"}
ABCresult
0XX0
1000
11X1
1011
123 1 require IO::Select;
124  
125 1 my $sel = IO::Select->new( $sock );
126  
127 1 undef $!;
128 1 my($r,$w,$e) = IO::Select::select(undef,$sel,$sel,$timeout);
129 1 ▶ if(@$e[0]) {
Branch: 3 branches
BranchTrueFalseTotal
if (@$e[0]) { } 0 1 1
elsif (not @$w[0]) { } 0 1 1
elsif (not CORE::connect($sock, $addr) || ($!{'EISCONN'} || $^O eq 'MSWin32' && $! == ($] < 5.019004 ? 10022 : 22))) { } 0 1 1
130 # Windows return from select after the timeout in case of
131 # WSAECONNREFUSED(10061) if exception set is not used.
132 # This behavior is different from Linux.
133 # Using the exception
134 # set we now emulate the behavior in Linux
135 # - Karthik Rajagopalan
136 0 $err = $sock->getsockopt(SOL_SOCKET,SO_ERROR);
137 0 $errstr = $@ = "connect: $err";
138 }
139 elsif(!@$w[0]) {
140 0 ▶ $err = $! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
Branch: 1 branch
BranchTrueFalseTotal
exists &Errno::ETIMEDOUT ? : 0 0 0
Condition0%0/3
$! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$! || (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1)
$! (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1)
Truth table0%0/3
A || B
A= $!B= (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1)
ABresult
1X1
011
000
141 0 $errstr = $@ = "connect: timeout";
142 }
143 ▶ elsif (!connect($sock,$addr) &&
Branch: 1 branch
BranchTrueFalseTotal
$] < 5.019004 ? : 0 0 0
Condition11%1/9
CORE::connect($sock, $addr) || ($!{'EISCONN'} || $^O eq 'MSWin32' && $! == ($] < 5.019004 ? 10022 : 22))
l!l&&r!l&&!r
100
$!{"EISCONN"} or $^O eq "MSWin32" and $! == ($] < "5.019004" ? 10022 : 22)
l!l&&r!l&&!r
000
$^O eq "MSWin32" and $! == ($] < "5.019004" ? 10022 : 22)
!ll&&!rl&&r
000
MC/DC0%0/4
CORE::connect($sock, $addr) || ($!{'EISCONN'} || $^O eq 'MSWin32' && $! == ($] < 5.019004 ? 10022 : 22))
CORE::connect($sock, $addr) $!{"EISCONN"} $^O eq "MSWin32" $! == ($] < "5.019004" ? 10022 : 22)
Truth table20%1/5
A || B or C and D
A= CORE::connect($sock, $addr)B= $!{"EISCONN"}C= $^O eq "MSWin32"D= $! == ($] < "5.019004" ? 10022 : 22)
ABCDresult
1XXX1
01XX1
00111
000X0
00100
144 not ($!{EISCONN} || ($^O eq 'MSWin32' &&
145 ($! == (($] < 5.019004) ? 10022 : Errno::EINVAL))))
146 ) {
147 # Some systems refuse to re-connect() to
148 # an already open socket and set errno to EISCONN.
149 # Windows sets errno to WSAEINVAL (10022) (pre-5.19.4) or
150 # EINVAL (22) (5.19.4 onwards).
151 0 $err = $!;
152 0 $errstr = $@ = "connect: $!";
153 }
154 }
155 ▶ elsif ($blocking || !($!{EINPROGRESS} || $!{EWOULDBLOCK})) {
Condition33%2/6
$blocking or not $!{"EINPROGRESS"} || $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
010
$!{'EINPROGRESS'} || $!{'EWOULDBLOCK'}
l!l&&r!l&&!r
001
MC/DC0%0/3
$blocking or not $!{"EINPROGRESS"} || $!{"EWOULDBLOCK"}
$blocking $!{'EINPROGRESS'} $!{'EWOULDBLOCK'}
Truth table25%1/4
A or not(B || C)
A= $blockingB= $!{'EINPROGRESS'}C= $!{'EWOULDBLOCK'}
ABCresult
1XX1
0001
01X0
0010
156 1 $err = $!;
157 1 $errstr = $@ = "connect: $!";
158 }
159 }
160  
161 14 ▶ $sock->blocking(1) if $blocking;
Branch: 1 branch
BranchTrueFalseTotal
if $blocking 1 13 14
162  
163 14 ▶ $! = $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 1 13 14
164  
165 14 ▶ $err ? undef : $sock;
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 1 13 14
166 }
167  
168 # Enable/disable blocking IO on sockets.
169 # Without args return the current status of blocking,
170 # with args change the mode as appropriate, returning the
171 # old setting, or in case of error during the mode change
172 # undef.
173  
174 10 ▶sub blocking {
Subroutine blocking: called CC=7 SCAR=35.8
Pod documented
175 10 my $sock = shift;
176  
177 10 ▶ return $sock->SUPER::blocking(@_)
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" and $^O ne "VMS" 10 0 10
Condition33%1/3
$^O ne "MSWin32" and $^O ne "VMS"
!ll&&!rl&&r
0010
MC/DC0%0/2
$^O ne "MSWin32" and $^O ne "VMS"
$^O ne "MSWin32" $^O ne "VMS"
Truth table33%1/3
A and B
A= $^O ne "MSWin32"B= $^O ne "VMS"
ABresult
0X0
100
111
178 if $^O ne 'MSWin32' && $^O ne 'VMS';
179  
180 # Windows handles blocking differently
181 #
182 # http://groups.google.co.uk/group/perl.perl5.porters/browse_thread/thread/b4e2b1d88280ddff/630b667a66e3509f?#630b667a66e3509f
183 # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/ioctlsocket_2.asp
184 #
185 # 0x8004667e is FIONBIO
186 #
187 # which is used to set blocking behaviour.
188  
189 # NOTE:
190 # This is a little confusing, the perl keyword for this is
191 # 'blocking' but the OS level behaviour is 'non-blocking', probably
192 # because sockets are blocking by default.
193 # Therefore internally we have to reverse the semantics.
194  
195 0 my $orig= !${*$sock}{io_sock_nonblocking};
196  
197 0 ▶ return $orig unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
198  
199 0 my $block = shift;
200  
201 0 ▶ if ( !$block != !$orig ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!$block != !$orig) 0 0 0
202 0 ▶ ${*$sock}{io_sock_nonblocking} = $block ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$block ? : 0 0 0
203 0 ▶ ioctl($sock, 0x8004667e, pack("L!",${*$sock}{io_sock_nonblocking}))
Branch: 1 branch
BranchTrueFalseTotal
ioctl $sock, 2147772030, pack("L!", do { *$sock }->{"io_sock_nonblocking"}) or return undef 0 0 0
204 or return undef;
205 }
206  
207 0 return $orig;
208 }
209  
210  
211 20 ▶sub close {
Subroutine close: called CC=2 SCAR=7.0
Pod undocumented
212 20 ▶ @_ == 1 or croak 'usage: $sock->close()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->close()") 20 0 20
213 20 my $sock = shift;
214 20 ${*$sock}{'io_socket_peername'} = undef;
215 20 $sock->SUPER::close();
216 }
217  
218 28 ▶sub bind {
Subroutine bind: called CC=3 SCAR=11.4
Pod documented
219 28 ▶ @_ == 2 or croak 'usage: $sock->bind(NAME)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$sock->bind(NAME)") 28 0 28
220 28 my $sock = shift;
221 28 my $addr = shift;
222  
223 28 ▶ return bind($sock, $addr) ? $sock
Branch: 1 branch
BranchTrueFalseTotal
CORE::bind($sock, $addr) ? : 28 0 28
224 : undef;
225 }
226  
227 20 ▶sub listen {
Subroutine listen: called CC=6 SCAR=22.0
Pod documented
228 20 ▶ @_ >= 1 && @_ <= 2 or croak 'usage: $sock->listen([QUEUE])';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 1 and @_ <= 2 or croak("usage: \$sock->listen([QUEUE])") 20 0 20
Condition33%1/3
@_ >= 1 and @_ <= 2
!ll&&!rl&&r
0020
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1 @_ <= 2
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 2
ABresult
0X0
100
111
229 20 my($sock,$queue) = @_;
230 20 ▶ $queue = 5
Branch: 1 branch
BranchTrueFalseTotal
unless $queue and $queue > 0 0 20 20
Condition33%1/3
$queue and $queue > 0
!ll&&!rl&&r
0020
MC/DC0%0/2
$queue and $queue > 0
$queue $queue > 0
Truth table33%1/3
A and B
A= $queueB= $queue > 0
ABresult
0X0
100
111
231 unless $queue && $queue > 0;
232  
233 20 ▶ return listen($sock, $queue) ? $sock
Branch: 1 branch
BranchTrueFalseTotal
CORE::listen($sock, $queue) ? : 20 0 20
234 : undef;
235 }
236  
237 21 ▶sub accept {
Subroutine accept: called CC=10 SCAR=24.0
Pod documented
238 21 ▶ @_ == 1 || @_ == 2 or croak 'usage $sock->accept([PKG])';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or croak("usage \$sock->accept([PKG])") 21 0 21
Condition33%1/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
2100
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table33%1/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
239 21 my $sock = shift;
240 21 ▶ my $pkg = shift || $sock;
Condition33%1/3
shift() || $sock
l!l&&r!l&&!r
0210
MC/DC0%0/2
shift() || $sock
shift() $sock
Truth table33%1/3
A || B
A= shift()B= $sock
ABresult
1X1
011
000
241 21 my $timeout = ${*$sock}{'io_socket_timeout'};
242 21 my $new = $pkg->new(Timeout => $timeout);
243 21 my $peer = undef;
244  
245 21 ▶ if(defined $timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeout) 18 3 21
246 18 require IO::Select;
247  
248 18 my $sel = IO::Select->new( $sock );
249  
250 18 ▶ unless ($sel->can_read($timeout)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sel->can_read($timeout)) 1 17 18
251 1 $errstr = $@ = 'accept: timeout';
252 1 ▶ $! = (exists &Errno::ETIMEDOUT ? &Errno::ETIMEDOUT : 1);
Branch: 1 branch
BranchTrueFalseTotal
exists &Errno::ETIMEDOUT ? : 1 0 1
253 1 return;
254 }
255 }
256  
257 20 ▶ $peer = accept($new,$sock)
Branch: 1 branch
BranchTrueFalseTotal
$peer = CORE::accept($new, $sock) or return 20 0 20
258 or return;
259  
260 20 ${*$new}{$_} = ${*$sock}{$_} for qw( io_socket_domain io_socket_type io_socket_proto );
261  
262 20 ▶ return wantarray ? ($new, $peer)
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 20 20
263 : $new;
264 }
265  
266 25 ▶sub sockname {
Subroutine sockname: called CC=2 SCAR=7.2
Pod documented
267 25 ▶ @_ == 1 or croak 'usage: $sock->sockname()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockname()") 25 0 25
268 25 getsockname($_[0]);
269 }
270  
271 2 ▶sub peername {
Subroutine peername: called CC=3 SCAR=12.0
Pod documented
272 2 ▶ @_ == 1 or croak 'usage: $sock->peername()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->peername()") 2 0 2
273 2 my($sock) = @_;
274 2 ▶ ${*$sock}{'io_socket_peername'} ||= getpeername($sock);
Condition33%1/3
do { *$sock }->{"io_socket_peername"} ||= getpeername $sock
l!l&&r!l&&!r
200
MC/DC0%0/2
do { *$sock }->{"io_socket_peername"} ||= getpeername $sock
do { *$sock }->{"io_socket_peername"} getpeername $sock
Truth table33%1/3
A ||= B
A= do { *$sock }->{"io_socket_peername"}B= getpeername $sock
ABresult
1X1
011
000
275 }
276  
277 2 ▶sub connected {
Subroutine connected: called CC=2 SCAR=7.1
Pod documented
278 2 ▶ @_ == 1 or croak 'usage: $sock->connected()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->connected()") 2 0 2
279 2 my($sock) = @_;
280 2 getpeername($sock);
281 }
282  
283 6 ▶sub send {
Subroutine send: called CC=10 SCAR=23.7
Pod documented
284 6 ▶ @_ >= 2 && @_ <= 4 or croak 'usage: $sock->send(BUF, [FLAGS, [TO]])';
Branch: 1 branch
BranchTrueFalseTotal
@_ >= 2 and @_ <= 4 or croak("usage: \$sock->send(BUF, [FLAGS, [TO]])") 6 0 6
Condition33%1/3
@_ >= 2 and @_ <= 4
!ll&&!rl&&r
006
MC/DC0%0/2
@_ >= 2 and @_ <= 4
@_ >= 2 @_ <= 4
Truth table33%1/3
A and B
A= @_ >= 2B= @_ <= 4
ABresult
0X0
100
111
285 6 my $sock = $_[0];
286 6 ▶ my $flags = $_[2] || 0;
Condition50%1/2
$_[2] || 0
l!l
06
MC/DC0%0/1
$_[2] || 0
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
287 6 my $peer;
288  
289 6 ▶ if ($_[3]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[3]) { } 2 4 6
elsif (not defined getpeername $sock) { } 1 3 4
290 # the caller explicitly requested a TO, so use it
291 # this is non-portable for "connected" UDP sockets
292 2 $peer = $_[3];
293 }
294 elsif (!defined getpeername($sock)) {
295 # we're not connected, so we require a peer from somewhere
296 1 $peer = $sock->peername;
297  
298 1 ▶ croak 'send: Cannot determine peer address'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $peer 0 1 1
299 unless(defined $peer);
300 }
301  
302 6 ▶ my $r = $peer
Branch: 1 branch
BranchTrueFalseTotal
$peer ? : 3 3 6
303 ? send($sock, $_[1], $flags, $peer)
304 : send($sock, $_[1], $flags);
305  
306 # remember who we send to, if it was successful
307 6 ▶ ${*$sock}{'io_socket_peername'} = $peer
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 4 and defined $r 2 4 6
Condition66%2/3
@_ == 4 and defined $r
!ll&&!rl&&r
402
MC/DC50%1/2
@_ == 4 and defined $r
@_ == 4 defined $r
Truth table66%2/3
A and B
A= @_ == 4B= defined $r
ABresult
0X0
100
111
308 if(@_ == 4 && defined $r);
309  
310 6 $r;
311 }
312  
313 6 ▶sub recv {
Subroutine recv: called CC=4 SCAR=15.0
Pod documented
314 6 ▶ @_ == 3 || @_ == 4 or croak 'usage: $sock->recv(BUF, LEN [, FLAGS])';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or @_ == 4 or croak("usage: \$sock->recv(BUF, LEN [, FLAGS])") 6 0 6
Condition33%1/3
@_ == 3 or @_ == 4
l!l&&r!l&&!r
600
MC/DC0%0/2
@_ == 3 or @_ == 4
@_ == 3 @_ == 4
Truth table33%1/3
A or B
A= @_ == 3B= @_ == 4
ABresult
1X1
011
000
315 6 my $sock = $_[0];
316 6 my $len = $_[2];
317 6 ▶ my $flags = $_[3] || 0;
Condition50%1/2
$_[3] || 0
l!l
06
MC/DC0%0/1
$_[3] || 0
$_[3]
Truth table50%1/2
A
A= $_[3]
Aresult
11
00
318  
319 # remember who we recv'd from
320 6 ${*$sock}{'io_socket_peername'} = recv($sock, $_[1]='', $len, $flags);
321 }
322  
323 0 ▶sub shutdown {
Subroutine shutdown: not called CC=2 SCAR=17.9
Pod documented
324 0 ▶ @_ == 2 or croak 'usage: $sock->shutdown(HOW)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 2 or croak("usage: \$sock->shutdown(HOW)") 0 0 0
325 0 my($sock, $how) = @_;
326 0 ${*$sock}{'io_socket_peername'} = undef;
327 0 shutdown($sock, $how);
328 }
329  
330 0 ▶sub setsockopt {
Subroutine setsockopt: not called CC=2 SCAR=17.9
Pod documented
331 0 ▶ @_ == 4 or croak '$sock->setsockopt(LEVEL, OPTNAME, OPTVAL)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("\$sock->setsockopt(LEVEL, OPTNAME, OPTVAL)") 0 0 0
332 0 setsockopt($_[0],$_[1],$_[2],$_[3]);
333 }
334  
335 18 my $intsize = length(pack("i",0));
336  
337 13 ▶sub getsockopt {
Subroutine getsockopt: called CC=4 SCAR=15.6
Pod documented
338 13 ▶ @_ == 3 or croak '$sock->getsockopt(LEVEL, OPTNAME)';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("\$sock->getsockopt(LEVEL, OPTNAME)") 13 0 13
339 13 my $r = getsockopt($_[0],$_[1],$_[2]);
340 # Just a guess
341 13 ▶ $r = unpack("i", $r)
Branch: 1 branch
BranchTrueFalseTotal
if defined $r and length $r == $intsize 13 0 13
Condition33%1/3
defined $r and length $r == $intsize
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $r and length $r == $intsize
defined $r length $r == $intsize
Truth table33%1/3
A and B
A= defined $rB= length $r == $intsize
ABresult
0X0
100
111
342 if(defined $r && length($r) == $intsize);
343 13 $r;
344 }
345  
346 13 ▶sub sockopt {
Subroutine sockopt: called CC=2 SCAR=7.2
Pod documented
347 13 my $sock = shift;
348 13 ▶ @_ == 1 ? $sock->getsockopt(SOL_SOCKET,@_)
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 13 0 13
349 : $sock->setsockopt(SOL_SOCKET,@_);
350 }
351  
352 0 ▶sub atmark {
Subroutine atmark: not called CC=2 SCAR=17.9
Pod documented
353 0 ▶ @_ == 1 or croak 'usage: $sock->atmark()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->atmark()") 0 0 0
354 0 my($sock) = @_;
355 0 sockatmark($sock);
356 }
357  
358 0 ▶sub timeout {
Subroutine timeout: not called CC=5 SCAR=34.0
Pod documented
359 0 ▶ @_ == 1 || @_ == 2 or croak 'usage: $sock->timeout([VALUE])';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or croak("usage: \$sock->timeout([VALUE])") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
360 0 my($sock,$val) = @_;
361 0 my $r = ${*$sock}{'io_socket_timeout'};
362  
363 0 ▶ ${*$sock}{'io_socket_timeout'} = defined $val ? 0 + $val : $val
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 2 0 0 0
defined $val ? : 0 0 0
364 if(@_ == 2);
365  
366 0 $r;
367 }
368  
369 10 ▶sub sockdomain {
Subroutine sockdomain: called CC=4 SCAR=14.0
Pod documented
370 10 ▶ @_ == 1 or croak 'usage: $sock->sockdomain()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->sockdomain()") 10 0 10
371 10 my $sock = shift;
372 10 ▶ if (!defined(${*$sock}{'io_socket_domain'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined do { *$sock }->{"io_socket_domain"}) 2 8 10
373 2 my $addr = $sock->sockname();
374 2 ▶ ${*$sock}{'io_socket_domain'} = sockaddr_family($addr)
Branch: 1 branch
BranchTrueFalseTotal
if defined $addr 2 0 2
375 if (defined($addr));
376 }
377 10 ${*$sock}{'io_socket_domain'};
378 }
379  
380 10 ▶sub socktype {
Subroutine socktype: called CC=4 SCAR=14.0
Pod documented
381 10 ▶ @_ == 1 or croak 'usage: $sock->socktype()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->socktype()") 10 0 10
382 10 my $sock = shift;
383 2 ${*$sock}{'io_socket_type'} = $sock->sockopt(Socket::SO_TYPE)
384 10 ▶ if (!defined(${*$sock}{'io_socket_type'}) && defined(eval{Socket::SO_TYPE}));
Branch: 1 branch
BranchTrueFalseTotal
if not defined do { *$sock }->{"io_socket_type"} and defined eval { do { 3 } } 2 8 10
Condition66%2/3
not defined do { *$sock }->{"io_socket_type"} and defined eval { do { 3 } }
!ll&&!rl&&r
802
MC/DC50%1/2
not defined do { *$sock }->{"io_socket_type"} and defined eval { do { 3 } }
not defined do { *$sock }->{"io_socket_type"} defined eval { do { 3 } }
Truth table66%2/3
not(A) and B
A= not defined do { *$sock }->{"io_socket_type"}B= defined eval { do { 3 } }
ABresult
0X0
100
111
385 10 ${*$sock}{'io_socket_type'}
386 }
387  
388 10 ▶sub protocol {
Subroutine protocol: called CC=4 SCAR=14.0
Pod documented
389 10 ▶ @_ == 1 or croak 'usage: $sock->protocol()';
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("usage: \$sock->protocol()") 10 0 10
390 10 my($sock) = @_;
391 5 ${*$sock}{'io_socket_proto'} = $sock->sockopt(Socket::SO_PROTOCOL)
392 10 ▶ if (!defined(${*$sock}{'io_socket_proto'}) && defined(eval{Socket::SO_PROTOCOL}));
Branch: 1 branch
BranchTrueFalseTotal
if not defined do { *$sock }->{"io_socket_proto"} and defined eval { do { 38 } } 5 5 10
Condition66%2/3
not defined do { *$sock }->{"io_socket_proto"} and defined eval { do { 38 } }
!ll&&!rl&&r
505
MC/DC50%1/2
not defined do { *$sock }->{"io_socket_proto"} and defined eval { do { 38 } }
not defined do { *$sock }->{"io_socket_proto"} defined eval { do { 38 } }
Truth table66%2/3
not(A) and B
A= not defined do { *$sock }->{"io_socket_proto"}B= defined eval { do { 38 } }
ABresult
0X0
100
111
393 10 ${*$sock}{'io_socket_proto'};
394 }
395  
396 18 1;
397  
398 __END__
« blib/lib/IO/Pipe.pm ↑ Summary blib/lib/IO/Select.pm »