« blib/lib/Linux/Event/WebSocket/_Random.pm
↑ Summary
blib/lib/Linux/Event/WebSocket/Client/_HTTPConnection.pm »
| 1 | package Linux::Event::WebSocket::_Engine; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use Linux::Event::WebSocket::_BQ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Linux::Event::WebSocket::_Frame; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Linux::Event::WebSocket::_UTF8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 47 | ▶ | sub new ($class, %option) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=18 SCAR=35.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 47 | my $connection = delete $option{connection}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 47 | ▶ | croak 'new(): connection object is required' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($connection) and $connection->can("write")
MC/DC0%0/2
builtin::blessed($connection) and $connection->can("write")
builtin::blessed($connection)
$connection->can("write")
Truth table33%1/3
A and B
A= builtin::blessed($connection)B= $connection->can("write")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | if !blessed($connection) || !$connection->can('write'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 47 | my $endpoint_type = delete $option{endpoint_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 47 | ▶ | croak 'new(): endpoint_type must be client or server' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not defined $endpoint_type or $endpoint_type ne "client" and $endpoint_type ne "server"
$endpoint_type ne "client" and $endpoint_type ne "server"
MC/DC0%0/3
not defined $endpoint_type or $endpoint_type ne "client" and $endpoint_type ne "server"
not defined $endpoint_type
$endpoint_type ne "client"
$endpoint_type ne "server"
Truth table50%2/4
not(A) or B and C
A= not defined $endpoint_typeB= $endpoint_type ne "client"C= $endpoint_type ne "server"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | if !defined($endpoint_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | || ($endpoint_type ne 'client' && $endpoint_type ne 'server'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 47 | my $message_handler_supplied = exists $option{message_handler}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 47 | my $message_handler = delete $option{message_handler}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 47 | ▶ | croak 'new(): message_handler must be a coderef' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $message_handler and ref $message_handler ne "CODE"
MC/DC0%0/2
defined $message_handler and ref $message_handler ne "CODE"
defined $message_handler
ref $message_handler ne "CODE"
Truth table66%2/3
A and B
A= defined $message_handlerB= ref $message_handler ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | if defined($message_handler) && ref($message_handler) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 47 | my $max_message_size = delete $option{max_message_size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 47 | ▶ | croak 'new(): max_message_size must be a positive integer' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $max_message_size or ref $max_message_size or not "$max_message_size" =~ /\A[0-9]+\z/u or $max_message_size < 1
not defined $max_message_size or ref $max_message_size or not "$max_message_size" =~ /\A[0-9]+\z/u
not defined $max_message_size or ref $max_message_size
MC/DC0%0/4
not defined $max_message_size or ref $max_message_size or not "$max_message_size" =~ /\A[0-9]+\z/u or $max_message_size < 1
not defined $max_message_size
ref $max_message_size
not "$max_message_size" =~ /\A[0-9]+\z/u
$max_message_size < 1
Truth table20%1/5
not(A) or B or not(C) or D
A= not defined $max_message_sizeB= ref $max_message_sizeC= not "$max_message_size" =~ /\A[0-9]+\z/uD= $max_message_size < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if !defined($max_message_size) || ref($max_message_size) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | || "$max_message_size" !~ /\A[0-9]+\z/ || $max_message_size < 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 47 | my $native = delete $option{native}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 47 | ▶ | croak 'new(): native must be a Linux::Event::WebSocket::_BQ object' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $native and not builtin::blessed($native) && $native->isa("Linux::Event::WebSocket::_BQ")
builtin::blessed($native) && $native->isa('Linux::Event::WebSocket::_BQ')
MC/DC0%0/3
defined $native and not builtin::blessed($native) && $native->isa("Linux::Event::WebSocket::_BQ")
defined $native
builtin::blessed($native)
$native->isa('Linux::Event::WebSocket::_BQ')
Truth table50%2/4
A and not(B && C)
A= defined $nativeB= builtin::blessed($native)C= $native->isa('Linux::Event::WebSocket::_BQ')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | if defined($native) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | && (!blessed($native) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | || !$native->isa('Linux::Event::WebSocket::_BQ')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 47 | ▶ | croak 'new(): unknown option(s): ' . join(', ', sort keys %option) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | if %option; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 47 | ▶ | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$native // "Linux::Event::WebSocket::_BQ"->new($endpoint_type, $max_message_size)
MC/DC0%0/2
$native // "Linux::Event::WebSocket::_BQ"->new($endpoint_type, $max_message_size)
$native
"Linux::Event::WebSocket::_BQ"->new($endpoint_type, $max_message_size)
Truth table66%2/3
A // B
A= $nativeB= "Linux::Event::WebSocket::_BQ"->new($endpoint_type, $max_message_size)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | connection => $connection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | endpoint_type => $endpoint_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | message_handler_supplied => $message_handler_supplied ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | message_handler => $message_handler, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | max_message_size => 0 + $max_message_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | native => $native // Linux::Event::WebSocket::_BQ->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $endpoint_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $max_message_size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sent_close => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | received_close => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | failed => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | in_feed => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | pending_end => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 47 | weaken($self->{connection}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 47 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 54 | ▶ | sub _connection ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_connection: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | return $self->{connection} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 54 | ▶ | // die "WebSocket connection was destroyed while its engine remained alive\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"connection"} // die("WebSocket connection was destroyed while its engine remained alive\n")
MC/DC0%0/1
$self->{"connection"} // die("WebSocket connection was destroyed while its engine remained alive\n")
$self->{"connection"}
Truth table50%1/2
A
A= $self->{"connection"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub is_closing ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_closing: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | return !!($self->{sent_close} || $self->{received_close}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'sent_close'} || $self->{'received_close'}
MC/DC0%0/2
$self->{'sent_close'} || $self->{'received_close'}
$self->{'sent_close'}
$self->{'received_close'}
Truth table33%1/3
A || B
A= $self->{'sent_close'}B= $self->{'received_close'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 51 | ▶ | sub _flush ($self, $connection = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flush: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 51 | ▶ | return 0 if $self->{in_feed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 42 | my $wire = $self->{native}->flush; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 42 | ▶ | return 0 if !length $wire; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 29 | ▶ | $connection //= $self->_connection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$connection //= $self->_connection
MC/DC0%0/2
$connection //= $self->_connection
$connection
$self->_connection
Truth table66%2/3
A //= B
A= $connectionB= $self->_connection
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 29 | ▶ | return 0 if $connection->is_closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 29 | return $connection->write($wire); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | ▶ | sub _queue_message ($self, $opcode, $bytes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_queue_message: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | $self->{native}->queue_message($opcode, $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 13 | return $self->_flush; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 12 | ▶ | sub send_text ($self, $bytes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_text: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | croak 'send_text(): WebSocket connection is closing' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | ▶ | if $self->{sent_close} || $self->{received_close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"sent_close"} or $self->{"received_close"}
MC/DC0%0/2
$self->{"sent_close"} or $self->{"received_close"}
$self->{"sent_close"}
$self->{"received_close"}
Truth table33%1/3
A or B
A= $self->{"sent_close"}B= $self->{"received_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | return $self->_queue_message(1, $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | ▶ | sub send_binary ($self, $bytes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_binary: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | croak 'send_binary(): WebSocket connection is closing' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 3 | ▶ | if $self->{sent_close} || $self->{received_close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"sent_close"} or $self->{"received_close"}
MC/DC0%0/2
$self->{"sent_close"} or $self->{"received_close"}
$self->{"sent_close"}
$self->{"received_close"}
Truth table33%1/3
A or B
A= $self->{"sent_close"}B= $self->{"received_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | return $self->_queue_message(2, $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | sub ping ($self, $bytes = '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ping: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | croak 'ping(): WebSocket connection is closing' if $self->is_closing; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | croak 'ping(): control frame payload exceeds 125 bytes' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | if length($bytes) > 125; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | return $self->_queue_message(9, $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | sub start_close ($self, $code, $reason = '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_close: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | ▶ | return $self if $self->{sent_close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | ▶ | croak 'close reason exceeds 123 bytes' if length($reason) > 123; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | my $number = Linux::Event::WebSocket::_Frame->close_code($code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | $self->{native}->queue_close($number, $reason); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | $self->{sent_close} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | my $connection = $self->_connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | $connection->_websocket_engine_closing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | $self->_flush($connection); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | ▶ | sub _failure_message ($error, $name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_failure_message: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | ▶ | return 'WebSocket message exceeds configured limit' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | if $name eq 'LIMIT_MAX_RECV_MSG_SIZE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 5 | ▶ | return 'WebSocket continuation frame received outside a fragmented message' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | if $name eq 'BAD_CONTINUATION'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | return 'WebSocket data frame received while a fragmented message is unfinished' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | if $name eq 'UNFINISHED_PARTIAL'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | return 'WebSocket close frame has a one-byte payload or invalid status code' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | if $name eq 'BAD_CLOSE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | return 'WebSocket close frame contains invalid UTF-8 reason' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | if $name eq 'BAD_UTF8'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return "WebSocket protocol error ($name)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 15 | ▶ | sub _fail ($self, $message, $code, $native_has_close = 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 15 | ▶ | return if $self->{failed}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 15 | my $connection = $self->_connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 15 | $connection->_websocket_engine_error($message); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 15 | ▶ | if (!$native_has_close && !$self->{sent_close} && !$connection->is_closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$native_has_close or $self->{"sent_close"} or $connection->is_closed
$native_has_close or $self->{"sent_close"}
MC/DC33%1/3
$native_has_close or $self->{"sent_close"} or $connection->is_closed
$native_has_close
$self->{"sent_close"}
$connection->is_closed
Truth table50%2/4
A or B or C
A= $native_has_closeB= $self->{"sent_close"}C= $connection->is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | $self->{native}->queue_close($code, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 15 | $self->{sent_close} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 15 | $connection->_websocket_engine_closing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 15 | $self->{pending_end} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 20 | ▶ | sub _deliver ($self, $opcode, $payload, $connection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deliver: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 20 | ▶ | return 0 if $self->{failed} || $self->{received_close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"failed"} or $self->{"received_close"}
MC/DC0%0/2
$self->{"failed"} or $self->{"received_close"}
$self->{"failed"}
$self->{"received_close"}
Truth table33%1/3
A or B
A= $self->{"failed"}B= $self->{"received_close"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 20 | ▶ | if (length($payload) > $self->{max_message_size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | $self->_fail('WebSocket message exceeds configured limit', 1009); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 19 | ▶ | my $type = $opcode == 1 ? 'text' : 'binary'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 19 | ▶ | if ($self->{message_handler_supplied}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 12 | ▶ | if (my $handler = $self->{message_handler}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | $handler->($connection, $payload, $type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 7 | $connection->_websocket_engine_message($payload, $type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 19 | return !$connection->is_closed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | ▶ | sub _handle_close ($self, $payload, $connection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_close: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | ▶ | return 0 if $self->{received_close}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 10 | my ($code, $reason); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 10 | ($code, $reason) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | Linux::Event::WebSocket::_Frame->parse_close_payload($payload); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $self->_fail($@, 1002); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 10 | my $decoded = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 10 | ▶ | if (length $reason) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 10 | $decoded = eval { Linux::Event::WebSocket::_UTF8->decode($reason) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 10 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $self->_fail('invalid UTF-8 in WebSocket close reason', 1007); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | $self->{received_close} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | $self->{sent_close} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 10 | $connection->_websocket_engine_closing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 10 | $connection->_websocket_engine_close($code, $decoded); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | $self->{pending_end} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 9 | ▶ | sub _bq_invalid_utf8 ($self, $connection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bq_invalid_utf8: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | return if $self->{failed} || $self->{received_close} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 9 | ▶ | || $connection->is_closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"failed"} or $self->{"received_close"} or $connection->is_closed
$self->{"failed"} or $self->{"received_close"}
MC/DC0%0/3
$self->{"failed"} or $self->{"received_close"} or $connection->is_closed
$self->{"failed"}
$self->{"received_close"}
$connection->is_closed
Truth table25%1/4
A or B or C
A= $self->{"failed"}B= $self->{"received_close"}C= $connection->is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 9 | $self->_fail('invalid UTF-8 in WebSocket text message', 1007); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 31 | ▶ | sub _bq_event ($self, $connection, $opcode, $payload) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bq_event: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | return if $self->{failed} || $self->{received_close} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 31 | ▶ | || $connection->is_closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$self->{"failed"} or $self->{"received_close"} or $connection->is_closed
$self->{"failed"} or $self->{"received_close"}
MC/DC33%1/3
$self->{"failed"} or $self->{"received_close"} or $connection->is_closed
$self->{"failed"}
$self->{"received_close"}
$connection->is_closed
Truth table50%2/4
A or B or C
A= $self->{"failed"}B= $self->{"received_close"}C= $connection->is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 30 | ▶ | if ($opcode == 1 || $opcode == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$opcode == 1 or $opcode == 2
MC/DC100%2/2
$opcode == 1 or $opcode == 2
$opcode == 1
$opcode == 2
Truth table100%3/3
A or B
A= $opcode == 1B= $opcode == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 20 | $self->_deliver($opcode, $payload, $connection); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } elsif ($opcode == 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 10 | $self->_handle_close($payload, $connection); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 30 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 26 | ▶ | sub _handle_bq_error ($self, $error, $error_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_bq_error: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 26 | ▶ | return if $self->{failed} || !$error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"failed"} or not $error
MC/DC100%2/2
$self->{"failed"} or not $error
$self->{"failed"}
not $error
Truth table100%3/3
A or not(B)
A= $self->{"failed"}B= not $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | ▶ | $self->_fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | _failure_message($error, $error_name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | $error_name eq 'LIMIT_MAX_RECV_MSG_SIZE' ? 1009 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | : $error_name eq 'BAD_UTF8' ? 1007 : 1002, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 34 | ▶ | sub _finish_feed ($self, $connection = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finish_feed: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 34 | ▶ | $connection //= $self->_connection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$connection //= $self->_connection
MC/DC0%0/2
$connection //= $self->_connection
$connection
$self->_connection
Truth table33%1/3
A //= B
A= $connectionB= $self->_connection
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 34 | $self->{in_feed} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 34 | ▶ | $self->_flush($connection) if !$connection->is_closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 34 | ▶ | if ($self->{pending_end} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"pending_end"} and not $connection->is_write_ended and not $connection->is_closed
$self->{"pending_end"} and not $connection->is_write_ended
MC/DC33%1/3
$self->{"pending_end"} and not $connection->is_write_ended and not $connection->is_closed
$self->{"pending_end"}
not $connection->is_write_ended
not $connection->is_closed
Truth table50%2/4
A and not(B) and not(C)
A= $self->{"pending_end"}B= not $connection->is_write_endedC= not $connection->is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | && !$connection->is_write_ended | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | && !$connection->is_closed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 24 | $self->{pending_end} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 24 | $connection->end; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 34 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 26 | ▶ | sub feed ($self, $bytes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
feed: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 26 | my $connection = $self->_connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | return if $self->{failed} || $self->{received_close} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 26 | ▶ | || $connection->is_closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->{"failed"} or $self->{"received_close"} or $connection->is_closed
$self->{"failed"} or $self->{"received_close"}
MC/DC0%0/3
$self->{"failed"} or $self->{"received_close"} or $connection->is_closed
$self->{"failed"}
$self->{"received_close"}
$connection->is_closed
Truth table25%1/4
A or B or C
A= $self->{"failed"}B= $self->{"received_close"}C= $connection->is_closed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 26 | $self->{in_feed} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | my ($error, $error_name) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 26 | $self->{native}->feed($self, $connection, $bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 26 | $self->_handle_bq_error($error, $error_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 26 | $self->_finish_feed($connection); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||