| 1 | package Linux::Event::_SocketConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 127 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 127 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 127 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 127 | our $VERSION = '0.120'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 127 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 127 | ▶ | use POSIX qw(ceil isfinite); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 127 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 127 | ▶ | use Socket qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | AF_INET AF_INET6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | IPPROTO_TCP SOL_SOCKET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | SO_KEEPALIVE SO_RCVBUF SO_SNDBUF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | TCP_KEEPCNT TCP_KEEPIDLE TCP_KEEPINTVL TCP_NODELAY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 127 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 127 | ▶ | use Socket (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 127 | ▶ | use Linux::Event::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 127 | ▶ | use constant _SO_BINDTODEVICE => Socket::SO_BINDTODEVICE(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 127 | ▶ | use constant _TCP_USER_TIMEOUT => Socket::TCP_USER_TIMEOUT(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 127 | my %SPEC = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | tcp_nodelay => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | level => IPPROTO_TCP, option => TCP_NODELAY, type => 'boolean', tcp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | keepalive => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | level => SOL_SOCKET, option => SO_KEEPALIVE, type => 'boolean', tcp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | keepalive_idle => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | level => IPPROTO_TCP, option => TCP_KEEPIDLE, type => 'positive', tcp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | keepalive_interval => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | level => IPPROTO_TCP, option => TCP_KEEPINTVL, type => 'positive', tcp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | keepalive_count => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | level => IPPROTO_TCP, option => TCP_KEEPCNT, type => 'positive', tcp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | tcp_user_timeout => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | level => IPPROTO_TCP, option => _TCP_USER_TIMEOUT, type => 'timeout', tcp => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | send_buffer => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | level => SOL_SOCKET, option => SO_SNDBUF, type => 'positive', tcp => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | receive_buffer => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | level => SOL_SOCKET, option => SO_RCVBUF, type => 'positive', tcp => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 309737 | ▶ | sub names () { sort keys %SPEC } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
names: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub is_option ($name) { exists $SPEC{$name} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_option: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 30 | ▶ | sub _target ($method, $name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_target: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 30 | ▶ | return "$method(): $name" if $method =~ /\A(?:new|connect)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 28 | return "$method $name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 30 | ▶ | sub normalize ($method, $name, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize: called CC=20 SCAR=36.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 30 | ▶ | croak "$method(): unknown socket option: $name" if !exists $SPEC{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 30 | my $type = $SPEC{$name}{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 30 | my $target = _target($method, $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 30 | ▶ | if ($type eq 'boolean') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 11 | ▶ | croak "$target must be zero or one" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $value or ref $value or not $value =~ /\A[01]\z/u
not defined $value or ref $value
MC/DC33%1/3
not defined $value or ref $value or not $value =~ /\A[01]\z/u
not defined $value
ref $value
not $value =~ /\A[01]\z/u
Truth table50%2/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not $value =~ /\A[01]\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | if !defined($value) || ref($value) || $value !~ /\A[01]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 10 | ▶ | return $value ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 19 | ▶ | if ($type eq 'positive') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 17 | ▶ | croak "$target must be a positive integer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $value or ref $value or not $value =~ /\A\d+\z/u or $value == 0
not defined $value or ref $value or not $value =~ /\A\d+\z/u
not defined $value or ref $value
MC/DC0%0/4
not defined $value or ref $value or not $value =~ /\A\d+\z/u or $value == 0
not defined $value
ref $value
not $value =~ /\A\d+\z/u
$value == 0
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $valueB= ref $valueC= not $value =~ /\A\d+\z/uD= $value == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | if !defined($value) || ref($value) || $value !~ /\A\d+\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | || $value == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 17 | ▶ | croak "$target must be at most 2147483647" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | if $value > 2_147_483_647; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 16 | return 0 + $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | my $seconds = !defined($value) || ref($value) || !looks_like_number($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $value or ref $value or not &looks_like_number($value)
not defined $value or ref $value
MC/DC0%0/3
not defined $value or ref $value or not &looks_like_number($value)
not defined $value
ref $value
not &looks_like_number($value)
Truth table25%1/4
not(A) or B or not(C)
A= not defined $valueB= ref $valueC= not &looks_like_number($value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ? undef : 0 + $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | croak "$target must be a non-negative number of seconds" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $seconds && isfinite($seconds) or $seconds < 0
defined $seconds && isfinite($seconds)
MC/DC0%0/3
not defined $seconds && isfinite($seconds) or $seconds < 0
defined $seconds
isfinite($seconds)
$seconds < 0
Truth table25%1/4
not(A && B) or C
A= defined $secondsB= isfinite($seconds)C= $seconds < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | if !defined($seconds) || !isfinite($seconds) || $seconds < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | croak "$target exceeds the Linux TCP_USER_TIMEOUT range" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | if $seconds > 4_294_967.295; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | return $seconds; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 103160 | ▶ | sub normalize_policy ($method, $policy) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_policy: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 103160 | for my $name (keys %$policy) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | next if !defined $policy->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $policy->{$name} = normalize($method, $name, $policy->{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 103160 | return $policy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 103160 | ▶ | sub extract ($method, $option) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 103160 | my %socket; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 103160 | for my $name (names()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 825280 | ▶ | $socket{$name} = delete $option->{$name} if exists $option->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 103160 | return normalize_policy($method, \%socket); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 17 | ▶ | sub _is_tcp ($family) { $family == AF_INET || $family == AF_INET6 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_tcp: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub _error ($operation, $name, $errno, $message = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | local $! = $errno; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | return Linux::Event::Error->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$errno || undef
$message // "$!"
MC/DC0%0/1
$errno || undef
$errno
MC/DC0%0/1
$message // "$!"
$message
Truth table50%1/2
A
A= $errno
Truth table50%1/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | type => 'socket_configuration', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | operation => $operation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | option => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | errno => $errno || undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | message => $message // "$!", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 16 | ▶ | sub _packed_value ($spec, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_packed_value: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 16 | ▶ | if ($spec->{type} eq 'timeout') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | my $milliseconds = $value == 0 ? 0 : ceil($value * 1000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return pack('I', $milliseconds); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 15 | return pack('i', $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 17 | ▶ | sub set_option ($fh, $family, $name, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_option: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 17 | ▶ | my $spec = $SPEC{$name} // croak "unknown socket option: $name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$SPEC{$name} // croak("unknown socket option: $name")
MC/DC0%0/1
$SPEC{$name} // croak("unknown socket option: $name")
$SPEC{$name}
Truth table50%1/2
A
A= $SPEC{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 17 | $value = normalize('socket option', $name, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | die _error('setsockopt', $name, 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | "$name is valid only for TCP sockets") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 17 | ▶ | if $spec->{tcp} && !_is_tcp($family); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$spec->{"tcp"} and not _is_tcp($family)
MC/DC100%2/2
$spec->{"tcp"} and not _is_tcp($family)
$spec->{"tcp"}
not _is_tcp($family)
Truth table100%3/3
A and not(B)
A= $spec->{"tcp"}B= not _is_tcp($family)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 16 | ▶ | if (!setsockopt( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | $fh, $spec->{level}, $spec->{option}, _packed_value($spec, $value), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $errno = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | die _error('setsockopt', $name, $errno); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | ▶ | sub get_option ($fh, $family, $name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_option: called CC=10 SCAR=24.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 14 | ▶ | my $spec = $SPEC{$name} // croak "unknown socket option: $name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$SPEC{$name} // croak("unknown socket option: $name")
MC/DC0%0/1
$SPEC{$name} // croak("unknown socket option: $name")
$SPEC{$name}
Truth table50%1/2
A
A= $SPEC{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | die _error('getsockopt', $name, 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | "$name is valid only for TCP sockets") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 14 | ▶ | if $spec->{tcp} && !_is_tcp($family); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec->{"tcp"} and not _is_tcp($family)
MC/DC0%0/2
$spec->{"tcp"} and not _is_tcp($family)
$spec->{"tcp"}
not _is_tcp($family)
Truth table66%2/3
A and not(B)
A= $spec->{"tcp"}B= not _is_tcp($family)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 14 | my $packed = getsockopt($fh, $spec->{level}, $spec->{option}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 14 | ▶ | if (!defined $packed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $errno = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | die _error('getsockopt', $name, $errno); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 14 | ▶ | die _error('getsockopt', $name, 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | "kernel returned an invalid value for $name") if length($packed) < 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 14 | ▶ | my $value = $spec->{type} eq 'timeout' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ? unpack('I', $packed) : unpack('i', $packed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 14 | ▶ | return $value / 1000 if $spec->{type} eq 'timeout'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 13 | ▶ | return $value ? 1 : 0 if $spec->{type} eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 103162 | ▶ | sub apply_policy ($fh, $family, $policy) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_policy: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 103162 | for my $name (names()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 825295 | ▶ | next if !exists($policy->{$name}) || !defined($policy->{$name}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $policy->{$name} and defined $policy->{$name}
MC/DC100%2/2
exists $policy->{$name} and defined $policy->{$name}
exists $policy->{$name}
defined $policy->{$name}
Truth table100%3/3
A and B
A= exists $policy->{$name}B= defined $policy->{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 12 | set_option($fh, $family, $name, $policy->{$name}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 103161 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub bind_device ($fh, $device) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind_device: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | croak 'bind_device must be a non-empty interface name' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not defined $device or ref $device or $device eq "" or $device =~ /\0/u
not defined $device or ref $device or $device eq ""
not defined $device or ref $device
MC/DC0%0/4
not defined $device or ref $device or $device eq "" or $device =~ /\0/u
not defined $device
ref $device
$device eq ""
$device =~ /\0/u
Truth table0%0/5
not(A) or B or C or D
A= not defined $deviceB= ref $deviceC= $device eq ""D= $device =~ /\0/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | if !defined($device) || ref($device) || $device eq '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | || $device =~ /\0/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if (!setsockopt($fh, SOL_SOCKET, _SO_BINDTODEVICE, "$device\0")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $errno = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | die _error('setsockopt', 'bind_device', $errno); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 127 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||