| 1 | package Net::WebSocket::Server; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use IO::Select; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Net::WebSocket::Server::Connection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = '0.003002'; | |||||||||||||||||||||||||||
| 15 | 3 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 3 | $SIG{PIPE} = 'IGNORE'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub new { | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | my %params = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | my $self = { | ||||||||||||||||||||||||||||
| 25 | listen => 80, | ||||||||||||||||||||||||||||
| 26 | silence_max => 20, | ||||||||||||||||||||||||||||
| 27 | tick_period => 0, | ||||||||||||||||||||||||||||
| 28 | watch_readable => [], | ||||||||||||||||||||||||||||
| 29 | watch_writable => [], | ||||||||||||||||||||||||||||
| 30 | ▶ | on_connect => sub{}, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | ▶ | on_tick => sub{}, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | ▶ | on_shutdown => sub{}, | |||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 1 | }; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | ▶ | while (my ($key, $value) = each %params ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 4 | ▶ | croak "Invalid $class parameter '$key'" unless exists $self->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | croak "$class parameter '$key' expected type is ".ref($self->{$key}) if ref $self->{$key} && ref $value ne ref $self->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self->{$key} and ref $value ne ref $self->{$key}
MC/DC0%0/2
ref $self->{$key} and ref $value ne ref $self->{$key}
ref $self->{$key}
ref $value ne ref $self->{$key}
Truth table66%2/3
A and B
A= ref $self->{$key}B= ref $value ne ref $self->{$key}
| |||||||||||||||||||||||||||||
| 38 | 4 | $self->{$key} = $value; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # send a ping every silence_max by checking whether data was received in the last silence_max/2 | ||||||||||||||||||||||||||||
| 44 | 1 | $self->{silence_checkinterval} = $self->{silence_max} / 2; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | foreach my $watchtype (qw(readable writable)) { | |||||||||||||||||||||||||||
| 47 | 2 | $self->{"select_$watchtype"} = IO::Select->new(); | |||||||||||||||||||||||||||
| 48 | 2 | my $key = "watch_$watchtype"; | |||||||||||||||||||||||||||
| 49 | 2 | ▶ | croak "$class parameter '$key' expects an arrayref containing an even number of elements" unless @{$self->{$key}} % 2 == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 2 | my @watch = @{$self->{$key}}; | |||||||||||||||||||||||||||
| 51 | 2 | $self->{$key} = {}; | |||||||||||||||||||||||||||
| 52 | 2 | $self->_watch($watchtype, @watch); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | return $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub watch_readable { | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
watch_readable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | croak "watch_readable expects an even number of arguments" unless @_ % 2 == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $self->_watch(readable => @_); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub watched_readable { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
watched_readable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $self->{watch_readable}{$_[0]}{cb} if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | return map {$_->{fh}, $_->{cb}} values %{$self->{watch_readable}}; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | sub watch_writable { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
watch_writable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | croak "watch_writable expects an even number of arguments" unless @_ % 2 == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $self->_watch(writable => @_); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub watched_writable { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
watched_writable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return $self->{watch_writable}{$_[0]}{cb} if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | return map {$_->{fh}, $_->{cb}} values %{$self->{watch_writable}}; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub _watch { | ||||||||||||||||||||||||||||
| 83 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_watch: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||
| 84 | 2 | my $watchtype = shift; | |||||||||||||||||||||||||||
| 85 | 2 | ▶ | croak "watch_$watchtype expects an even number of arguments after the type" unless @_ % 2 == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 2 | ▶ | for (my $i = 0; $i < @_; $i+=2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 2 | my ($fh, $cb) = ($_[$i], $_[$i+1]); | |||||||||||||||||||||||||||
| 88 | 2 | ▶ | croak "watch_$watchtype expects the second value of each pair to be a coderef, but element $i was not" unless ref $cb eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | if ($self->{"watch_$watchtype"}{$fh}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | carp "watch_$watchtype was given a filehandle at index $i which is already being watched; ignoring!"; | |||||||||||||||||||||||||||
| 91 | 0 | next; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 2 | $self->{"select_$watchtype"}->add($fh); | |||||||||||||||||||||||||||
| 94 | 2 | $self->{"watch_$watchtype"}{$fh} = {fh=>$fh, cb=>$cb}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub unwatch_readable { | ||||||||||||||||||||||||||||
| 99 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unwatch_readable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 1 | $self->_unwatch(readable => @_); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub unwatch_writable { | ||||||||||||||||||||||||||||
| 104 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unwatch_writable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 1 | $self->_unwatch(writable => @_); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub _unwatch { | ||||||||||||||||||||||||||||
| 109 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_unwatch: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 110 | 2 | my $watchtype = shift; | |||||||||||||||||||||||||||
| 111 | 2 | foreach my $fh (@_) { | |||||||||||||||||||||||||||
| 112 | 2 | $self->{"select_$watchtype"}->remove($fh); | |||||||||||||||||||||||||||
| 113 | 2 | delete $self->{"watch_$watchtype"}{$fh}; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub on { | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
on: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | while (my ($key, $value) = each %params ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | croak "Invalid event '$key'" unless exists $self->{"on_$key"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | croak "Expected a coderef for event '$key'" unless ref $value eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | $self->{"on_$key"} = $value; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub start { | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
start: called CC=24 SCAR=38.8
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 1 | ▶ | if (ref $self->{listen}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | # if we got a server, make sure it's valid by clearing errors and checking errors anyway; if there's still an error, it's closed | ||||||||||||||||||||||||||||
| 133 | 1 | $self->{listen}->clearerr; | |||||||||||||||||||||||||||
| 134 | croak "failed to start websocket server; the TCP server provided via 'listen' is invalid. (is the listening socket is closed? are you trying to reuse a server that has already shut down?)" | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | if $self->{listen}->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | } else { | ||||||||||||||||||||||||||||
| 137 | # if we merely got a port, set up a reasonable default tcp server | ||||||||||||||||||||||||||||
| 138 | $self->{listen} = IO::Socket::INET->new( | ||||||||||||||||||||||||||||
| 139 | Listen => 5, | ||||||||||||||||||||||||||||
| 140 | LocalPort => $self->{listen}, | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | Proto => 'tcp', | ||||||||||||||||||||||||||
|
Condition0%0/3
'IO::Socket::INET'->new('Listen', 5, 'LocalPort', $self->{'listen'}, 'Proto', 'tcp', 'ReuseAddr', 1) || croak("failed to listen on port $self->{'listen'}: $!")
MC/DC0%0/2
'IO::Socket::INET'->new('Listen', 5, 'LocalPort', $self->{'listen'}, 'Proto', 'tcp', 'ReuseAddr', 1) || croak("failed to listen on port $self->{'listen'}: $!")
'IO::Socket::INET'->new('Listen', 5, 'LocalPort', $self->{'listen'}, 'Proto', 'tcp', 'ReuseAddr', 1)
croak("failed to listen on port $self->{'listen'}: $!")
Truth table0%0/3
A || B
A= 'IO::Socket::INET'->new('Listen', 5, 'LocalPort', $self->{'listen'}, 'Proto', 'tcp', 'ReuseAddr', 1)B= croak("failed to listen on port $self->{'listen'}: $!")
| |||||||||||||||||||||||||||||
| 142 | ReuseAddr => 1, | ||||||||||||||||||||||||||||
| 143 | ) || croak "failed to listen on port $self->{listen}: $!"; | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | $self->{select_readable}->add($self->{listen}); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 1 | $self->{conns} = {}; | |||||||||||||||||||||||||||
| 149 | 1 | ▶ | my $silence_nextcheck = $self->{silence_max} ? (time + $self->{silence_checkinterval}) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 1 | ▶ | my $tick_next = $self->{tick_period} ? (time + $self->{tick_period}) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 1 | ▶ | while (%{$self->{conns}} || $self->{listen}->opened) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
%{$self->{"conns"};} or $self->{"listen"}->opened
MC/DC100%2/2
%{$self->{"conns"};} or $self->{"listen"}->opened
%{$self->{"conns"};}
$self->{"listen"}->opened
Truth table100%3/3
A or B
A= %{$self->{"conns"};}B= $self->{"listen"}->opened
| |||||||||||||||||||||||||||||
| 153 | 22 | ▶ | my $silence_checktimeout = $self->{silence_max} ? ($silence_nextcheck - time) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 22 | ▶ | my $tick_timeout = $self->{tick_period} ? ($tick_next - time) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 22 | my $timeout = min(grep {defined} ($silence_checktimeout, $tick_timeout)); | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 22 | my ($ready_read, $ready_write, undef) = IO::Select->select($self->{select_readable}, $self->{select_writable}, undef, $timeout); | |||||||||||||||||||||||||||
| 158 | 22 | ▶ | foreach my $fh ($ready_read ? @$ready_read : ()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 21 | ▶ | if ($fh == $self->{listen}) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 160 | 1 | my $sock = $self->{listen}->accept; | |||||||||||||||||||||||||||
| 161 | 1 | ▶ | next unless $sock; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 1 | my $conn = new Net::WebSocket::Server::Connection(socket => $sock, server => $self); | |||||||||||||||||||||||||||
| 163 | 1 | $self->{conns}{$sock} = {conn=>$conn, lastrecv=>time}; | |||||||||||||||||||||||||||
| 164 | 1 | $self->{select_readable}->add($sock); | |||||||||||||||||||||||||||
| 165 | 1 | $self->{on_connect}($self, $conn); | |||||||||||||||||||||||||||
| 166 | } elsif ($self->{watch_readable}{$fh}) { | ||||||||||||||||||||||||||||
| 167 | 1 | $self->{watch_readable}{$fh}{cb}($self, $fh); | |||||||||||||||||||||||||||
| 168 | } elsif ($self->{conns}{$fh}) { | ||||||||||||||||||||||||||||
| 169 | 19 | my $connmeta = $self->{conns}{$fh}; | |||||||||||||||||||||||||||
| 170 | 19 | $connmeta->{lastrecv} = time; | |||||||||||||||||||||||||||
| 171 | 19 | $connmeta->{conn}->recv(); | |||||||||||||||||||||||||||
| 172 | } else { | ||||||||||||||||||||||||||||
| 173 | 0 | warn "filehandle $fh became readable, but no handler took responsibility for it; removing it"; | |||||||||||||||||||||||||||
| 174 | 0 | $self->{select_readable}->remove($fh); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 22 | ▶ | foreach my $fh ($ready_write ? @$ready_write : ()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 1 | ▶ | if ($self->{watch_writable}{$fh}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 1 | $self->{watch_writable}{$fh}{cb}($self, $fh); | |||||||||||||||||||||||||||
| 181 | } else { | ||||||||||||||||||||||||||||
| 182 | 0 | warn "filehandle $fh became writable, but no handler took responsibility for it; removing it"; | |||||||||||||||||||||||||||
| 183 | 0 | $self->{select_writable}->remove($fh); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 22 | ▶ | if ($self->{silence_max}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 22 | my $now = time; | |||||||||||||||||||||||||||
| 189 | 22 | ▶ | if ($silence_nextcheck < $now) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | my $lastcheck = $silence_nextcheck - $self->{silence_checkinterval}; | |||||||||||||||||||||||||||
| 191 | 0 | $_->{conn}->send('ping') for grep { $_->{lastrecv} < $lastcheck } values %{$self->{conns}}; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | $silence_nextcheck = $now + $self->{silence_checkinterval}; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 22 | ▶ | if ($self->{tick_period} && $tick_next < time) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"tick_period"} and $tick_next < &Net::WebSocket::Server::time()
MC/DC0%0/2
$self->{"tick_period"} and $tick_next < &Net::WebSocket::Server::time()
$self->{"tick_period"}
$tick_next < &Net::WebSocket::Server::time()
Truth table33%1/3
A and B
A= $self->{"tick_period"}B= $tick_next < &Net::WebSocket::Server::time()
| |||||||||||||||||||||||||||||
| 198 | 0 | $self->{on_tick}($self); | |||||||||||||||||||||||||||
| 199 | 0 | $tick_next += $self->{tick_period}; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 2 | ▶ | sub connections { map {$_->{conn}} values %{$_[0]{conns}} } | ||||||||||||||||||||||||||
|
Subroutine
connections: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | sub shutdown { | ||||||||||||||||||||||||||||
| 207 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 1 | $self->{on_shutdown}($self); | |||||||||||||||||||||||||||
| 209 | 1 | $self->{select_readable}->remove($self->{listen}); | |||||||||||||||||||||||||||
| 210 | 1 | $self->{listen}->close(); | |||||||||||||||||||||||||||
| 211 | 1 | $_->disconnect(1001) for $self->connections; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | sub disconnect { | ||||||||||||||||||||||||||||
| 215 | 1 | ▶ | my ($self, $fh) = @_; | ||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 216 | 1 | $self->{select_readable}->remove($fh); | |||||||||||||||||||||||||||
| 217 | 1 | $fh->close(); | |||||||||||||||||||||||||||
| 218 | 1 | delete $self->{conns}{$fh}; | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 3 | 1; # End of Net::WebSocket::Server | |||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | __END__ | ||||||||||||||||||||||||||||