| 1 | package Linux::Event::HTTP::Server; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 19 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use Scalar::Util qw(weaken refaddr); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Unblock::HTTP::Server 0.03; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Linux::Event::IO::Sock::Listener; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Linux::Event::Kernel::Timer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use Linux::Event::HTTP::_Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use Linux::Event::HTTP::_Stream; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 19 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 23 | ▶ | sub new ($class, %option) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=31 SCAR=49.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 23 | my $loop = delete $option{loop}; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 23 | Linux::Event::HTTP::_Config::loop($loop); | |||||||||||||||||||||||||||||||||||||||||
| 16 | 23 | my $stream_class = Linux::Event::HTTP::_Config::stream_class(\%option); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 23 | my %protocols = Linux::Event::HTTP::_Config::protocols(\%option); | |||||||||||||||||||||||||||||||||||||||||
| 18 | # Keep the capability check for mixed or incomplete installations. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # Check once at construction, before binding, never per request. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | ▶ | if ($protocols{http1}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | require Unblock::HTTP1::Server; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 23 | ▶ | croak 'new(): Unblock::HTTP1::Server lacks drain() required for HTTP/1 graceful shutdown; install a compatible Unblock::HTTP1 build' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | unless Unblock::HTTP1::Server->can('drain'); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 22 | ▶ | my $quic = delete($option{quic}) // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $option{"quic"} // {}
MC/DC0%0/1
delete $option{"quic"} // {}
delete $option{"quic"}
Truth table50%1/2
A
A= delete $option{"quic"}
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 22 | ▶ | croak 'new(): quic must be a hash reference' unless ref($quic) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 22 | ▶ | croak 'new(): quic requires http3 => 1' if %$quic && !$protocols{http3}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
%$quic and not $protocols{"http3"}
MC/DC0%0/2
%$quic and not $protocols{"http3"}
%$quic
not $protocols{"http3"}
Truth table33%1/3
A and not(B)
A= %$quicB= not $protocols{"http3"}
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 22 | my %callbacks; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 22 | for my $name (qw(on_headers on_request on_error on_websocket on_handoff)) { | |||||||||||||||||||||||||||||||||||||||||
| 30 | 110 | ▶ | $callbacks{$name} = delete $option{$name} if exists $option{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # H2/H3 Extended CONNECT WebSocket output must be scheduled outside | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # the native protocol receive stack. H1 Upgrade does not use this hook. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $defer = sub ($callback) { $loop->defer($callback) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 22 | my $definition = Unblock::HTTP::Server->new( | |||||||||||||||||||||||||||||||||||||||||
| 36 | %protocols, %callbacks, defer => $defer, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | my $self = bless { loop => $loop, definition => $definition, | |||||||||||||||||||||||||||||||||||||||||
| 39 | connections => {} }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | my $state = { server => $self }; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 22 | weaken($state->{server}); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | my %stream = (class => $stream_class, data => $state); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 22 | for my $name (qw(tls tuning)) { | |||||||||||||||||||||||||||||||||||||||||
| 44 | 44 | ▶ | $stream{$name} = delete $option{$name} if exists $option{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | croak 'new(): HTTP/2 Server requires tls for ALPN negotiation' | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 22 | ▶ | if exists($protocols{http2}) && !exists($stream{tls}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $protocols{"http2"} and not exists $stream{"tls"}
MC/DC0%0/2
exists $protocols{"http2"} and not exists $stream{"tls"}
exists $protocols{"http2"}
not exists $stream{"tls"}
Truth table33%1/3
A and not(B)
A= exists $protocols{"http2"}B= not exists $stream{"tls"}
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 22 | ▶ | if (exists $protocols{http3}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | croak 'new(): HTTP3 requires a concrete host (not a wildcard)' | ||||||||||||||||||||||||||||||||||||||||||
| 50 | unless defined($option{host}) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | && $option{host} ne '0.0.0.0' && $option{host} ne '::'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $option{"host"} and $option{"host"} ne "0.0.0.0" and $option{"host"} ne "::"
defined $option{"host"} and $option{"host"} ne "0.0.0.0"
MC/DC0%0/3
defined $option{"host"} and $option{"host"} ne "0.0.0.0" and $option{"host"} ne "::"
defined $option{"host"}
$option{"host"} ne "0.0.0.0"
$option{"host"} ne "::"
Truth table0%0/4
A and B and C
A= defined $option{"host"}B= $option{"host"} ne "0.0.0.0"C= $option{"host"} ne "::"
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | croak 'new(): HTTP3 requires TLS cert_file and key_file' | ||||||||||||||||||||||||||||||||||||||||||
| 53 | unless ref($stream{tls}) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | && $stream{tls}{cert_file} && $stream{tls}{key_file}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $stream{"tls"} eq "HASH" and $stream{"tls"}{"cert_file"} and $stream{"tls"}{"key_file"}
ref $stream{"tls"} eq "HASH" and $stream{"tls"}{"cert_file"}
MC/DC0%0/3
ref $stream{"tls"} eq "HASH" and $stream{"tls"}{"cert_file"} and $stream{"tls"}{"key_file"}
ref $stream{"tls"} eq "HASH"
$stream{"tls"}{"cert_file"}
$stream{"tls"}{"key_file"}
Truth table0%0/4
A and B and C
A= ref $stream{"tls"} eq "HASH"B= $stream{"tls"}{"cert_file"}C= $stream{"tls"}{"key_file"}
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | croak 'new(): HTTP3-only listeners are not implemented yet' | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless exists($protocols{http1}) || exists($protocols{http2}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $protocols{"http1"} or exists $protocols{"http2"}
MC/DC0%0/2
exists $protocols{"http1"} or exists $protocols{"http2"}
exists $protocols{"http1"}
exists $protocols{"http2"}
Truth table0%0/3
A or B
A= exists $protocols{"http1"}B= exists $protocols{"http2"}
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 22 | ▶ | if (exists $stream{tls}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | ▶ | croak 'new(): tls must be a hash reference' unless ref($stream{tls}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | ▶ | croak 'new(): HTTP Server owns TLS alpn' if exists $stream{tls}{alpn}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | $stream{tls} = { %{ $stream{tls} }, alpn => [$definition->alpn_protocols] }; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 22 | my $on_error = delete $option{on_listener_error}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 22 | my %listen; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 22 | for my $name (qw(host port path fh backlog reuseaddr reuseport v6only unlink_on_close)) { | |||||||||||||||||||||||||||||||||||||||||
| 66 | 198 | ▶ | $listen{$name} = delete $option{$name} if exists $option{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 22 | ▶ | croak 'new(): unknown option: ' . join(', ', sort keys %option) if %option; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | $self->{listener} = Linux::Event::IO::Sock::Listener->new( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | loop => $loop, %listen, stream => \%stream, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 21 | ▶ | on_accept => sub ($listener, $stream) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 21 | my $server = $state->{server}; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 21 | ▶ | $server ? $server->_track($stream) : $stream->close; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 22 | ▶ | (defined($on_error) ? (on_error => $on_error) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 22 | ▶ | if (exists $protocols{http3}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | require Unblock::HTTP::QUIC; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | require Linux::Event::HTTP::_QUICSocket; | |||||||||||||||||||||||||||||||||||||||||
| 80 | my $socket = Linux::Event::HTTP::_QUICSocket->new( | ||||||||||||||||||||||||||||||||||||||||||
| 81 | loop => $loop, host => $listen{host}, port => $self->port, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | (defined($on_error) ? (on_error => $on_error) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | on_progress => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $server = $state->{server} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $server->_quic_progress; | |||||||||||||||||||||||||||||||||||||||||
| 86 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | my $manager = Unblock::HTTP::QUIC->server( | ||||||||||||||||||||||||||||||||||||||||||
| 89 | server => $definition, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | certificate_file => $stream{tls}{cert_file}, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | private_key_file => $stream{tls}{key_file}, | ||||||||||||||||||||||||||||||||||||||||||
| 92 | %$quic, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | send => $socket->send_callback, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | set_timeout => $socket->set_timeout_callback, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | on_ready => sub ($engine, $quic_manager) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $server = $state->{server} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $server->_quic_ready($engine); | |||||||||||||||||||||||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $self->{quic} = { socket => $socket, manager => $manager }; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $socket->start($manager); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub loop ($self) { $self->{loop} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub listener ($self) { $self->{listener} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listener: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub host ($self) { $self->{listener}->host } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 21 | ▶ | sub port ($self) { $self->{listener}->port } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
port: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub pause ($self) { $self->{listener}->pause; return $self } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pause: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub resume ($self) { $self->{listener}->resume; return $self } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resume: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 22 | ▶ | sub close ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=6 SCAR=28.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 22 | $self->{listener}->close; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 22 | ▶ | if ($self->{quic} && !$self->{quic_closing}++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"quic"} and not $self->{"quic_closing"}++
MC/DC0%0/2
$self->{"quic"} and not $self->{"quic_closing"}++
$self->{"quic"}
not $self->{"quic_closing"}++
Truth table33%1/3
A and not(B)
A= $self->{"quic"}B= not $self->{"quic_closing"}++
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | for my $engine ($self->{quic}{manager}->sessions) { | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $engine->shutdown_notice unless $engine->shutdown_notice_sent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $engine->shutdown unless $engine->shutdown_started; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->_quic_progress; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 38 | ▶ | sub connection_count ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection_count: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 38 | my $count = scalar keys %{ $self->{connections} }; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 38 | ▶ | $count += scalar($self->{quic}{manager}->sessions) if $self->{quic}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 38 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 10 | ▶ | sub shutdown ($self, %option) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=11 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | my $grace = delete($option{grace}) // 30; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $option{"grace"} // 30
MC/DC100%1/1
delete $option{"grace"} // 30
delete $option{"grace"}
Truth table100%2/2
A
A= delete $option{"grace"}
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 10 | my $complete = delete $option{on_complete}; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 10 | ▶ | croak 'shutdown(): grace must be a non-negative number of seconds' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $grace and $grace =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
MC/DC0%0/2
not ref $grace and $grace =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
not ref $grace
$grace =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
Truth table33%1/3
not(A) and B
A= not ref $graceB= $grace =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | unless !ref($grace) && $grace =~ /\A(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 10 | ▶ | croak 'shutdown(): on_complete must be a coderef' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $complete and ref $complete ne "CODE"
MC/DC0%0/2
defined $complete and ref $complete ne "CODE"
defined $complete
ref $complete ne "CODE"
Truth table66%2/3
A and B
A= defined $completeB= ref $complete ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | if defined($complete) && ref($complete) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 10 | ▶ | croak 'shutdown(): unknown option: ' . join(', ', sort keys %option) if %option; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 10 | ▶ | return $self if $self->{shutdown}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 9 | $self->{shutdown} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 9 | $self->{shutdown_complete} = $complete; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 9 | $self->close; | |||||||||||||||||||||||||||||||||||||||||
| 141 | # A synchronous close can remove a stream while this snapshot is drained. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | for my $stream (values %{ $self->{connections} }) { | |||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | $stream->_http_drain; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | ▶ | if ($self->connection_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 4 | my $weak = $self; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | weaken($weak); | |||||||||||||||||||||||||||||||||||||||||
| 148 | $self->{shutdown_timer} = Linux::Event::Kernel::Timer->new( | ||||||||||||||||||||||||||||||||||||||||||
| 149 | loop => $self->{loop}, after => $grace, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | on_timer => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | my $server = $weak or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $_->close for values %{ $server->{connections} }; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | if (my $quic = delete $server->{quic}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $quic->{socket}->close; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | $server->_shutdown_done; | |||||||||||||||||||||||||||||||||||||||||
| 157 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 9 | ▶ | $self->_quic_progress if $self->{quic}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | $self->_shutdown_done; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 18 | ▶ | sub _shutdown_done ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shutdown_done: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 18 | ▶ | return unless $self->{shutdown} && !$self->connection_count && !$self->{quic}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"shutdown"} and not $self->connection_count and not $self->{"quic"}
$self->{"shutdown"} and not $self->connection_count
MC/DC33%1/3
$self->{"shutdown"} and not $self->connection_count and not $self->{"quic"}
$self->{"shutdown"}
not $self->connection_count
not $self->{"quic"}
Truth table50%2/4
A and not(B) and not(C)
A= $self->{"shutdown"}B= not $self->connection_countC= not $self->{"quic"}
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 13 | ▶ | return if $self->{shutdown_notified}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 9 | my $timer = delete $self->{shutdown_timer}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 9 | ▶ | $timer->cancel if $timer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | my $complete = delete $self->{shutdown_complete}; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 9 | ▶ | $complete->($self) if $complete; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub _quic_ready ($self, $engine) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quic_ready: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($self->{quic_closing}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | $engine->quic->close unless $engine->quic->closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub _quic_progress ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quic_progress: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my $quic = $self->{quic} or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return unless $self->{quic_closing}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my @sessions = $quic->{manager}->sessions; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | for my $engine (@sessions) { | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $connection = $engine->quic; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | next if $connection->closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if ($self->{shutdown} && ($engine->failed || $engine->drained)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"shutdown"} and $engine->failed || $engine->drained
$engine->failed or $engine->drained
MC/DC0%0/3
$self->{"shutdown"} and $engine->failed || $engine->drained
$self->{"shutdown"}
$engine->failed
$engine->drained
Truth table0%0/4
A and B or C
A= $self->{"shutdown"}B= $engine->failedC= $engine->drained
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $connection->close; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # If no sessions are admitted, a handshake in progress has no HTTP | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # application transaction to preserve. Close the UDP listener. | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (!@sessions) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | delete $self->{quic}; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $quic->{socket}->close; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | $self->_shutdown_done if $self->{shutdown}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 39 | ▶ | sub _track ($self, $stream) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_track: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 39 | ▶ | return if $stream->is_closed; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 39 | ▶ | return $stream->close if $self->{shutdown}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 39 | $self->{connections}{refaddr($stream)} = $stream; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 39 | return; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 18 | ▶ | sub _attach ($self, $stream) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attach: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($self->{shutdown}) { $stream->close; return } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 18 | $self->_track($stream); | |||||||||||||||||||||||||||||||||||||||||
| 214 | return $self->{definition}->attach_stream( | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 18 | transport => $stream, alpn => $stream->selected_alpn, | |||||||||||||||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 21 | ▶ | sub _closed ($self, $stream) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_closed: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 21 | delete $self->{connections}{refaddr($stream)}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 21 | ▶ | $self->_shutdown_done if $self->{shutdown}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 21 | return; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | __END__ | ||||||||||||||||||||||||||||||||||||||||||