| 1 | package Linux::Event::Connect; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | use Socket qw( | |||||||||||||||||||||||||||||||||||||||||
| 11 | AF_INET AF_INET6 AF_UNIX | ||||||||||||||||||||||||||||||||||||||||||
| 12 | SOCK_STREAM | ||||||||||||||||||||||||||||||||||||||||||
| 13 | SOL_SOCKET SO_ERROR | ||||||||||||||||||||||||||||||||||||||||||
| 14 | inet_pton | ||||||||||||||||||||||||||||||||||||||||||
| 15 | pack_sockaddr_in | ||||||||||||||||||||||||||||||||||||||||||
| 16 | pack_sockaddr_in6 | ||||||||||||||||||||||||||||||||||||||||||
| 17 | pack_sockaddr_un | ||||||||||||||||||||||||||||||||||||||||||
| 18 | getaddrinfo | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use Errno (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | use constant { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | S_NEW => 0, | |||||||||||||||||||||||||||||||||||||||||
| 24 | S_CONNECTING => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | S_DONE => 2, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 11 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | ▶ | sub new ($class, %args) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=71 SCAR=51.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 517 | my $loop = delete $args{loop}; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 517 | ▶ | croak "loop is required" unless defined $loop && ref $loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $loop and ref $loop
MC/DC0%0/2
defined $loop and ref $loop
defined $loop
ref $loop
Truth table33%1/3
A and B
A= defined $loopB= ref $loop
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 517 | ▶ | my $timeout_s = exists $args{timeout_s} ? delete $args{timeout_s} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 517 | my $data = delete $args{data}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 517 | ▶ | my $on_connect = exists $args{on_connect} ? delete $args{on_connect} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 517 | ▶ | my $on_error = exists $args{on_error} ? delete $args{on_error} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 517 | ▶ | my $nonblocking = exists $args{nonblocking} ? delete $args{nonblocking} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 517 | ▶ | croak "nonblocking must be true" unless $nonblocking; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 516 | ▶ | croak "on_connect must be a coderef" if defined $on_connect && ref($on_connect) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_connect and ref $on_connect ne "CODE"
MC/DC0%0/2
defined $on_connect and ref $on_connect ne "CODE"
defined $on_connect
ref $on_connect ne "CODE"
Truth table66%2/3
A and B
A= defined $on_connectB= ref $on_connect ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 516 | ▶ | croak "on_error must be a coderef" if defined $on_error && ref($on_error) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $on_error and ref $on_error ne "CODE"
MC/DC0%0/2
defined $on_error and ref $on_error ne "CODE"
defined $on_error
ref $on_error ne "CODE"
Truth table66%2/3
A and B
A= defined $on_errorB= ref $on_error ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 516 | ▶ | if (defined $timeout_s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 507 | ▶ | croak "timeout_s must be a number >= 0" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $timeout_s < 0
MC/DC0%0/2
not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u or $timeout_s < 0
not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/u
$timeout_s < 0
Truth table33%1/3
not(A) or B
A= not $timeout_s =~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/uB= $timeout_s < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | if $timeout_s !~ /\A(?:\d+(?:\.\d*)?|\.\d+)\z/ || $timeout_s < 0; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 507 | $timeout_s = 0 + $timeout_s; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Address mode selection (exactly one): | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 516 | ▶ | my $have_hostport = (exists $args{host} || exists $args{port}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $args{"host"} or exists $args{"port"}
MC/DC100%2/2
exists $args{"host"} or exists $args{"port"}
exists $args{"host"}
exists $args{"port"}
Truth table100%3/3
A or B
A= exists $args{"host"}B= exists $args{"port"}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 516 | ▶ | my $have_unix = exists $args{unix} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 516 | ▶ | my $have_sockaddr = exists $args{sockaddr} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 516 | ▶ | my $modes = ($have_hostport ? 1 : 0) + ($have_unix ? 1 : 0) + ($have_sockaddr ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 516 | ▶ | croak "exactly one address mode is required (host/port, unix, or sockaddr)" if $modes != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 515 | my ($host, $port, $unix, $sockaddr, $family); | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 515 | ▶ | if ($have_hostport) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 511 | $host = delete $args{host}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 511 | $port = delete $args{port}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 511 | ▶ | croak "host is required" unless defined $host; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 510 | ▶ | croak "host must be a non-empty string" if ref($host) || $host eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $host or $host eq ""
MC/DC0%0/2
ref $host or $host eq ""
ref $host
$host eq ""
Truth table33%1/3
A or B
A= ref $hostB= $host eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 510 | ▶ | croak "port is required" unless defined $port; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 509 | ▶ | croak "port must be an integer" if ref($port) || $port !~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $port or not $port =~ /\A\d+\z/u
MC/DC50%1/2
ref $port or not $port =~ /\A\d+\z/u
ref $port
not $port =~ /\A\d+\z/u
Truth table66%2/3
A or not(B)
A= ref $portB= not $port =~ /\A\d+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 508 | $port = 0 + $port; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 508 | ▶ | croak "port out of range" if $port < 0 || $port > 65535; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$port < 0 or $port > 65535
MC/DC0%0/2
$port < 0 or $port > 65535
$port < 0
$port > 65535
Truth table33%1/3
A or B
A= $port < 0B= $port > 65535
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 508 | ▶ | croak "family is not allowed in host/port mode" if exists $args{family}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 507 | ▶ | croak "sockaddr is not allowed in host/port mode" if exists $args{sockaddr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 507 | ▶ | croak "unix is not allowed in host/port mode" if exists $args{unix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 507 | ▶ | croak "type is not allowed in host/port mode" if exists $args{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 507 | ▶ | croak "proto is not allowed in host/port mode" if exists $args{proto}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | elsif ($have_unix) { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $unix = delete $args{unix}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | croak "unix must be a non-empty string" if !defined($unix) || ref($unix) || $unix eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $unix or ref $unix or $unix eq ""
not defined $unix or ref $unix
MC/DC0%0/3
not defined $unix or ref $unix or $unix eq ""
not defined $unix
ref $unix
$unix eq ""
Truth table25%1/4
not(A) or B or C
A= not defined $unixB= ref $unixC= $unix eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | croak "host is not allowed in unix mode" if exists $args{host}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | croak "port is not allowed in unix mode" if exists $args{port}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | croak "sockaddr is not allowed in unix mode" if exists $args{sockaddr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | croak "family is not allowed in unix mode" if exists $args{family}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | croak "type is not allowed in unix mode" if exists $args{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | croak "proto is not allowed in unix mode" if exists $args{proto}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | else { # sockaddr mode | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | $sockaddr = delete $args{sockaddr}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | croak "sockaddr must be a defined scalar" if !defined($sockaddr) || ref($sockaddr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $sockaddr or ref $sockaddr
MC/DC0%0/2
not defined $sockaddr or ref $sockaddr
not defined $sockaddr
ref $sockaddr
Truth table33%1/3
not(A) or B
A= not defined $sockaddrB= ref $sockaddr
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | $family = delete $args{family}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | croak "family is required in sockaddr mode" unless defined $family; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | croak "family must be a numeric AF_* constant" if ref($family) || $family !~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $family or not $family =~ /\A\d+\z/u
MC/DC0%0/2
ref $family or not $family =~ /\A\d+\z/u
ref $family
not $family =~ /\A\d+\z/u
Truth table33%1/3
A or not(B)
A= ref $familyB= not $family =~ /\A\d+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | $family = 0 + $family; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | croak "host is not allowed in sockaddr mode" if exists $args{host}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | croak "port is not allowed in sockaddr mode" if exists $args{port}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | croak "unix is not allowed in sockaddr mode" if exists $args{unix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | croak "type is not allowed in sockaddr mode (v0.001)" if exists $args{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | croak "proto is not allowed in sockaddr mode (v0.001)" if exists $args{proto}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 509 | ▶ | if (%args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | my @k = sort keys %args; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | croak "unknown option(s): " . join(", ", @k); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 508 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 112 | _loop => $loop, | ||||||||||||||||||||||||||||||||||||||||||
| 113 | _data => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | _timeout_s => $timeout_s, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | _cb_ok => $on_connect, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | _cb_err => $on_error, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | _state => S_NEW, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | _done => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | _cancelled => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | _errno => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | _gai_error => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | _cand => [], | ||||||||||||||||||||||||||||||||||||||||||
| 125 | _idx => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | _fh => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | _watch => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | _timer_id => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # Normalize to candidate list | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 508 | ▶ | if (defined $unix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | push @{ $self->{_cand} }, [ AF_UNIX, pack_sockaddr_un($unix) ]; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | elsif (defined $sockaddr) { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | push @{ $self->{_cand} }, [ $family, $sockaddr ]; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # host/port mode: IP literal fast-path, else synchronous getaddrinfo | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 506 | my $h = $host; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 506 | $h =~ s/\A[ \t\r\n]+//; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 506 | $h =~ s/[ \t\r\n]+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 506 | ▶ | if (index($h, '[') == 0 && substr($h, -1) eq ']') { $h = substr($h, 1, -1) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($h, "[") == 0 and substr($h, -1) eq "]"
MC/DC50%1/2
index($h, "[") == 0 and substr($h, -1) eq "]"
index($h, "[") == 0
substr($h, -1) eq "]"
Truth table66%2/3
A and B
A= index($h, "[") == 0B= substr($h, -1) eq "]"
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 506 | my $p4 = inet_pton(AF_INET, $h); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 506 | ▶ | if (defined $p4) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 505 | push @{ $self->{_cand} }, [ AF_INET, pack_sockaddr_in($port, $p4) ]; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my $p6 = inet_pton(AF_INET6, $h); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | if (defined $p6) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | push @{ $self->{_cand} }, [ AF_INET6, pack_sockaddr_in6($port, $p6) ]; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my ($err, @res) = getaddrinfo($host, $port, { socktype => SOCK_STREAM }); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | $self->{_gai_error} = "$err"; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | my $mapped = ($err =~ /NONAME|NODATA|NO_DATA/i) ? Errno::ENOENT() : Errno::EIO(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | $self->_finalize_err($mapped); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | for my $r (@res) { | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $fam = $r->{family}; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $sa = $r->{addr}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | next unless defined $fam && defined $sa; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $fam and defined $sa
MC/DC0%0/2
defined $fam and defined $sa
defined $fam
defined $sa
Truth table0%0/3
A and B
A= defined $famB= defined $sa
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | push @{ $self->{_cand} }, [ $fam, $sa ]; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if (!@{ $self->{_cand} }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->_finalize_err(Errno::ENOENT()); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 507 | $self->{_state} = S_CONNECTING; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 507 | ▶ | $self->_arm_timeout if defined $timeout_s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 507 | $self->_attempt_next; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 507 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | ▶ | sub cancel ($self) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cancel: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | return if $self->{_done}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | $self->{_cancelled} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | $self->{_done} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | $self->{_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | $self->_teardown; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | $self->{_cb_ok} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | $self->{_cb_err} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub is_pending ($self) { return !$self->{_done} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_pending: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | ▶ | sub is_done ($self) { return $self->{_done} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_done: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | sub fh ($self) { return $self->{_fh} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | sub errno ($self) { return $self->{_errno} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errno: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | ▶ | sub gai_error ($self) { return $self->{_gai_error} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gai_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | ▶ | sub _arm_timeout ($self) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_arm_timeout: called CC=1 SCAR=2.9
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | ▶ | my $id = $self->{_loop}->after($self->{_timeout_s}, sub ($loop) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | return if $self->{_done} || $self->{_cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_done"} or $self->{"_cancelled"}
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"}
$self->{"_cancelled"}
Truth table0%0/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $self->_finalize_err(Errno::ETIMEDOUT()); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 507 | }); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 507 | $self->{_timer_id} = $id; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 507 | return; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | ▶ | sub _attempt_next ($self) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attempt_next: called CC=10 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1008 | ▶ | return if $self->{_done} || $self->{_cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"}
$self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 1008 | my $cand = $self->{_cand}; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 1008 | my $n = @$cand; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 1008 | ▶ | while ($self->{_idx} < $n) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 507 | my ($family, $sockaddr) = @{ $cand->[ $self->{_idx}++ ] }; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 507 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 507 | ▶ | if (!socket($fh, $family, SOCK_STREAM, 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->{_errno} = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 507 | my $flags = fcntl($fh, F_GETFL, 0); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 507 | ▶ | if (!defined $flags) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $self->{_errno} = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 507 | ▶ | if (!fcntl($fh, F_SETFL, $flags | O_NONBLOCK)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->{_errno} = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 507 | $self->{_fh} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 507 | ▶ | if (connect($fh, $sockaddr)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | $self->_finalize_ok($fh); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 506 | my $e = 0 + $!; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 506 | $self->{_errno} = $e; | |||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 506 | ▶ | if ($e == Errno::EINPROGRESS()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | ▶ | my $w = $self->{_loop}->watch($fh, | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=29.4
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | write => sub ($loop, $fh2, $watcher) { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | ▶ | return if $self->{_done} || $self->{_cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"}
$self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | my $raw = getsockopt($fh2, SOL_SOCKET, SO_ERROR); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | my $soerr = 0; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | ▶ | $soerr = unpack("i", $raw) if defined($raw) && length($raw) >= 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $raw and length $raw >= 4
MC/DC0%0/2
defined $raw and length $raw >= 4
defined $raw
length $raw >= 4
Truth table33%1/3
A and B
A= defined $rawB= length $raw >= 4
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | if ($soerr == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | $self->_finalize_ok($fh2); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $self->{_errno} = $soerr; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | eval { close $fh2; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $self->{_fh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | # Drop watcher before attempting next | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if (my $ww = delete $self->{_watch}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | eval { $ww->close; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $self->_attempt_next; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 273 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | ▶ | error => sub ($loop, $fh2, $watcher) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 501 | ▶ | return if $self->{_done} || $self->{_cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"}
$self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 501 | my $raw = getsockopt($fh2, SOL_SOCKET, SO_ERROR); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 501 | my $soerr = 0; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 501 | ▶ | $soerr = unpack("i", $raw) if defined($raw) && length($raw) >= 4; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $raw and length $raw >= 4
MC/DC0%0/2
defined $raw and length $raw >= 4
defined $raw
length $raw >= 4
Truth table33%1/3
A and B
A= defined $rawB= length $raw >= 4
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 501 | ▶ | $soerr ||= (0 + $!); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$soerr ||= 0 + $!
MC/DC0%0/2
$soerr ||= 0 + $!
$soerr
0 + $!
Truth table33%1/3
A ||= B
A= $soerrB= 0 + $!
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 501 | $self->{_errno} = $soerr; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 501 | eval { close $fh2; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 501 | $self->{_fh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 501 | ▶ | if (my $ww = delete $self->{_watch}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 501 | eval { $ww->close; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 501 | $self->_attempt_next; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 501 | return; | |||||||||||||||||||||||||||||||||||||||||
| 292 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 506 | ); | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 506 | $self->{_watch} = $w; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 506 | return; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | # Immediate failure, try next | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $self->{_fh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | # exhausted candidates: report last errno if set, else EIO | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 501 | my $last = $self->{_errno}; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 501 | ▶ | $last = Errno::EIO() if !defined $last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 501 | $self->_finalize_err($last); | |||||||||||||||||||||||||||||||||||||||||
| 308 | 501 | return; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | ▶ | sub _teardown ($self) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_teardown: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 503 | ▶ | if (my $w = delete $self->{_watch}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | eval { $w->close; 1 } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | # fallback if Watcher has no close | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 1 | ▶ | if (my $fh = $self->{_fh}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | eval { $self->{_loop}->unwatch($fh); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 503 | ▶ | if (defined(my $id = delete $self->{_timer_id})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 502 | eval { $self->{_loop}->cancel($id); 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 503 | ▶ | if (my $fh = delete $self->{_fh}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | eval { close $fh; 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 503 | return; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | ▶ | sub _finalize_ok ($self, $fh) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finalize_ok: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 5 | ▶ | return if $self->{_done} || $self->{_cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"}
$self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 5 | $self->{_done} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 5 | $self->{_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | # Make inert before callbacks | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 5 | my $cb = $self->{_cb_ok}; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | my $data = $self->{_data}; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 5 | $self->{_cb_ok} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 5 | $self->{_cb_err} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # Teardown watcher/timer, but do NOT close $fh on success | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 5 | ▶ | if (my $w = delete $self->{_watch}) { eval { $w->close; 1 } } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 5 | ▶ | if (defined(my $id = delete $self->{_timer_id})) { eval { $self->{_loop}->cancel($id); 1 } } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 5 | $self->{_fh} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 5 | ▶ | $cb->($self, $fh, $data) if $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | ▶ | sub _finalize_err ($self, $errno) { | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finalize_err: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 502 | ▶ | return if $self->{_done} || $self->{_cancelled}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_done"} or $self->{"_cancelled"}
MC/DC0%0/2
$self->{"_done"} or $self->{"_cancelled"}
$self->{"_done"}
$self->{"_cancelled"}
Truth table33%1/3
A or B
A= $self->{"_done"}B= $self->{"_cancelled"}
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 502 | $self->{_errno} = $errno; | |||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 502 | $self->{_done} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 502 | $self->{_state} = S_DONE; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 502 | my $cb = $self->{_cb_err}; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 502 | my $data = $self->{_data}; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 502 | $self->{_cb_ok} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 364 | 502 | $self->{_cb_err} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 502 | $self->_teardown; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 502 | ▶ | $cb->($self, $errno, $data) if $cb; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 502 | return; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | __END__ | ||||||||||||||||||||||||||||||||||||||||||