| 1 | package POE::Component::Server::Inet; | ||||||||||||||||||||||||||||
| 2 | 5 | $POE::Component::Server::Inet::VERSION = '0.06'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: a super-server daemon implementation in POE | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use POE qw(Wheel::SocketFactory Wheel::Run Wheel::ReadWrite Filter::Stream); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Net::Netmask; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | sub spawn { | ||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 4 | my $package = shift; | |||||||||||||||||||||||||||
| 14 | 4 | my %opts = @_; | |||||||||||||||||||||||||||
| 15 | 4 | $opts{lc $_} = delete $opts{$_} for keys %opts; | |||||||||||||||||||||||||||
| 16 | 4 | my $options = delete $opts{options}; | |||||||||||||||||||||||||||
| 17 | 4 | my $self = bless \%opts, $package; | |||||||||||||||||||||||||||
| 18 | 4 | ▶ | $self->{session_id} = POE::Session->create( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | object_states => [ | ||||||||||||||||||||||||||||
| 20 | $self => { shutdown => '_shutdown', | ||||||||||||||||||||||||||||
| 21 | add_tcp => '_add_tcp', | ||||||||||||||||||||||||||||
| 22 | del_tcp => '_del_tcp', | ||||||||||||||||||||||||||||
| 23 | # add_udp => '_add_udp', | ||||||||||||||||||||||||||||
| 24 | # del_udp => '_del_udp', | ||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | $self => [ qw(_start _accept_new_client _accept_failed _get_datagram _sig_child _client_input _client_flushed _client_error _wheel_out _wheel_close _wheel_error _wheel_alarm) ], | ||||||||||||||||||||||||||||
| 27 | ], | ||||||||||||||||||||||||||||
| 28 | heap => $self, | ||||||||||||||||||||||||||||
| 29 | ( ref($options) eq 'HASH' ? ( options => $options ) : () ), | ||||||||||||||||||||||||||||
| 30 | )->ID(); | ||||||||||||||||||||||||||||
| 31 | 4 | return $self; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub session_id { | ||||||||||||||||||||||||||
|
Subroutine
session_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | return $_[0]->{session_id}; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub _conn_exists { | ||||||||||||||||||||||||||
|
Subroutine
_conn_exists: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($self,$wheel_id) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | return 0 unless $wheel_id and defined $self->{clients}->{ $wheel_id }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$wheel_id and defined $self->{"clients"}{$wheel_id}
MC/DC0%0/2
$wheel_id and defined $self->{"clients"}{$wheel_id}
$wheel_id
defined $self->{"clients"}{$wheel_id}
Truth table0%0/3
A and B
A= $wheel_idB= defined $self->{"clients"}{$wheel_id}
| |||||||||||||||||||||||||||||
| 41 | 0 | return 1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | sub _start { | ||||||||||||||||||||||||||
|
Subroutine
_start: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 45 | 4 | my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER]; | |||||||||||||||||||||||||||
| 46 | 4 | $self->{session_id} = $_[SESSION]->ID(); | |||||||||||||||||||||||||||
| 47 | 4 | ▶ | if ( $self->{alias} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $kernel->alias_set( $self->{alias} ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||
| 51 | 4 | $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 4 | $self->{stream_filter} = POE::Filter::Stream->new(); | |||||||||||||||||||||||||||
| 54 | 4 | return; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | ▶ | sub shutdown { | ||||||||||||||||||||||||||
|
Subroutine
shutdown: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | 4 | $poe_kernel->call( $self->{session_id}, 'shutdown' ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 4 | ▶ | sub _shutdown { | ||||||||||||||||||||||||||
|
Subroutine
_shutdown: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 63 | 4 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||
| 64 | 4 | $kernel->alarm_remove_all(); | |||||||||||||||||||||||||||
| 65 | 4 | $kernel->alias_remove( $_ ) for $kernel->alias_list(); | |||||||||||||||||||||||||||
| 66 | 4 | ▶ | $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) unless $self->{alias}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | # Shutdown TCP listeners | ||||||||||||||||||||||||||||
| 68 | 4 | delete $self->{tcp_ports}; | |||||||||||||||||||||||||||
| 69 | # Shutdown UDP listeners | ||||||||||||||||||||||||||||
| 70 | 4 | $kernel->select_read( $_->{socket} ) for values %{ $self->{udp_ports} }; | |||||||||||||||||||||||||||
| 71 | # Shutdown wheels. | ||||||||||||||||||||||||||||
| 72 | 4 | delete $self->{clients}; | |||||||||||||||||||||||||||
| 73 | 4 | delete $self->{wheels}; | |||||||||||||||||||||||||||
| 74 | 4 | return; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | ▶ | sub add_tcp { | ||||||||||||||||||||||||||
|
Subroutine
add_tcp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 4 | $poe_kernel->call( $self->{session_id}, 'add_tcp', @_ ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub del_tcp { | ||||||||||||||||||||||||||
|
Subroutine
del_tcp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 0 | $poe_kernel->call( $self->{session_id}, 'del_tcp', @_ ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | sub _add_tcp { | ||||||||||||||||||||||||||
|
Subroutine
_add_tcp: called CC=12 SCAR=33.7
| |||||||||||||||||||||||||||||
| 89 | 4 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||
| 90 | 4 | my $args; | |||||||||||||||||||||||||||
| 91 | 4 | ▶ | if ( ref( $_[ARG0] ) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | $args = { %{ $_[ARG0] } }; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||
| 95 | 4 | $args = { @_[ARG0..$#_] }; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 4 | ▶ | unless ( defined $args->{port} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | warn "You must specify a 'port' parameter\n"; | |||||||||||||||||||||||||||
| 99 | 0 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( grep { $_->{port} eq $args->{port} } values %{ $self->{tcp_ports} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | warn "There already exists a TCP port definition for '$args->{port}'\n"; | |||||||||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 4 | ▶ | unless ( $args->{program} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | warn "You must specify a 'program' parameter\n"; | |||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | 4 | ▶ | delete $args->{programargs} unless $args->{programargs} and ref $args->{programargs} eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"programargs"} and ref $args->{"programargs"} eq "ARRAY"
MC/DC0%0/2
$args->{"programargs"} and ref $args->{"programargs"} eq "ARRAY"
$args->{"programargs"}
ref $args->{"programargs"} eq "ARRAY"
Truth table33%1/3
A and B
A= $args->{"programargs"}B= ref $args->{"programargs"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 110 | 4 | ▶ | if ( $args->{allow} and !$args->{allow}->isa('Net::Netmask') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"allow"} and not $args->{"allow"}->isa("Net::Netmask")
MC/DC0%0/2
$args->{"allow"} and not $args->{"allow"}->isa("Net::Netmask")
$args->{"allow"}
not $args->{"allow"}->isa("Net::Netmask")
Truth table33%1/3
A and not(B)
A= $args->{"allow"}B= not $args->{"allow"}->isa("Net::Netmask")
| |||||||||||||||||||||||||||||
| 111 | 0 | warn "'allow' parameter must be a Net::Netmask object, ignoring.\n"; | |||||||||||||||||||||||||||
| 112 | 0 | delete $args->{allow}; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 4 | ▶ | if ( $args->{deny} and !$args->{deny}->isa('Net::Netmask') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{"deny"} and not $args->{"deny"}->isa("Net::Netmask")
MC/DC0%0/2
$args->{"deny"} and not $args->{"deny"}->isa("Net::Netmask")
$args->{"deny"}
not $args->{"deny"}->isa("Net::Netmask")
Truth table33%1/3
A and not(B)
A= $args->{"deny"}B= not $args->{"deny"}->isa("Net::Netmask")
| |||||||||||||||||||||||||||||
| 115 | 0 | warn "'deny' parameter must be a Net::Netmask object, ignoring.\n"; | |||||||||||||||||||||||||||
| 116 | 0 | delete $args->{deny}; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | my $sockfactory = POE::Wheel::SocketFactory->new( | ||||||||||||||||||||||||||||
| 119 | ( defined $args->{bindaddress} ? ( BindAddress => $args->{bindaddress} ) : () ), | ||||||||||||||||||||||||||||
| 120 | BindPort => $args->{port}, | ||||||||||||||||||||||||||||
| 121 | 4 | ▶ | SuccessEvent => '_accept_new_client', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | FailureEvent => '_accept_failed', | ||||||||||||||||||||||||||||
| 123 | SocketDomain => AF_INET, | ||||||||||||||||||||||||||||
| 124 | SocketType => SOCK_STREAM, | ||||||||||||||||||||||||||||
| 125 | SocketProtocol => 'tcp', | ||||||||||||||||||||||||||||
| 126 | Reuse => 'on', | ||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||
| 128 | 4 | $args->{sockfactory} = $sockfactory; | |||||||||||||||||||||||||||
| 129 | 4 | $self->{tcp_ports}->{ $sockfactory->ID() } = $args; | |||||||||||||||||||||||||||
| 130 | 4 | my $port = ( sockaddr_in( $sockfactory->getsockname() ) )[0]; | |||||||||||||||||||||||||||
| 131 | 4 | $args->{port} = $port; | |||||||||||||||||||||||||||
| 132 | 4 | return $port; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub _del_tcp { | ||||||||||||||||||||||||||
|
Subroutine
_del_tcp: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 136 | 0 | my ($kernel,$self) = @_[KERNEL,OBJECT]; | |||||||||||||||||||||||||||
| 137 | 0 | my $args; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( ref( $_[ARG0] ) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | $args = { %{ $_[ARG0] } }; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||
| 142 | 0 | $args = { @_[ARG0..$#_] }; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | unless ( defined $args->{port} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | warn "You must specify a 'port' parameter\n"; | |||||||||||||||||||||||||||
| 146 | 0 | return; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | foreach my $sockfactory_id ( keys %{ $self->{tcp_ports} } ) { | |||||||||||||||||||||||||||
| 149 | 0 | ▶ | next unless $self->{tcp_ports}->{ $sockfactory_id }->{port} eq $args->{port}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | delete $self->{tcp_ports}->{ $sockfactory_id }; | |||||||||||||||||||||||||||
| 151 | 0 | return; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 0 | return; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub _accept_failed { | ||||||||||||||||||||||||||
|
Subroutine
_accept_failed: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 158 | 0 | my ($kernel,$self,$wheel_id) = @_[KERNEL,OBJECT,ARG3]; | |||||||||||||||||||||||||||
| 159 | 0 | warn join(' ', @_[ARG0..ARG2] ), "\n"; | |||||||||||||||||||||||||||
| 160 | 0 | delete $self->{tcp_ports}->{ $wheel_id }->{sockfactory}; | |||||||||||||||||||||||||||
| 161 | 0 | return; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 14 | ▶ | sub _accept_new_client { | ||||||||||||||||||||||||||
|
Subroutine
_accept_new_client: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 165 | 14 | my ($kernel,$self,$socket,$peeraddr,$peerport,$factory_id) = @_[KERNEL,OBJECT,ARG0 .. ARG3]; | |||||||||||||||||||||||||||
| 166 | 14 | $peeraddr = inet_ntoa($peeraddr); | |||||||||||||||||||||||||||
| 167 | # Check if 'accept' or 'deny' | ||||||||||||||||||||||||||||
| 168 | my $client = POE::Wheel::ReadWrite->new ( | ||||||||||||||||||||||||||||
| 169 | Handle => $socket, | ||||||||||||||||||||||||||||
| 170 | Filter => $self->{stream_filter}, | ||||||||||||||||||||||||||||
| 171 | 14 | InputEvent => '_client_input', | |||||||||||||||||||||||||||
| 172 | ErrorEvent => '_client_error', | ||||||||||||||||||||||||||||
| 173 | FlushedEvent => '_client_flushed', | ||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||
| 175 | 14 | my $args = $self->{tcp_ports}->{ $factory_id }; | |||||||||||||||||||||||||||
| 176 | my $wheel = POE::Wheel::Run->new( | ||||||||||||||||||||||||||||
| 177 | Program => $args->{program}, | ||||||||||||||||||||||||||||
| 178 | ProgramArgs => $args->{programargs}, | ||||||||||||||||||||||||||||
| 179 | StdioFilter => $self->{stream_filter}, | ||||||||||||||||||||||||||||
| 180 | StderrFilter => $self->{stream_filter}, | ||||||||||||||||||||||||||||
| 181 | StdoutEvent => '_wheel_out', # Received data from the child's STDOUT. | ||||||||||||||||||||||||||||
| 182 | StderrEvent => '_wheel_out', # Received data from the child's STDERR. | ||||||||||||||||||||||||||||
| 183 | ErrorEvent => '_wheel_error', # An I/O error occurred. | ||||||||||||||||||||||||||||
| 184 | CloseEvent => '_wheel_close', # Child closed all output handles. | ||||||||||||||||||||||||||||
| 185 | ( defined $args->{user} ? ( User => $args->{user} ) : () ), | ||||||||||||||||||||||||||||
| 186 | 14 | ▶ | ( defined $args->{group} ? ( Group => $args->{group} ) : () ), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | 14 | my $client_id = $client->ID(); | |||||||||||||||||||||||||||
| 189 | 14 | my $wheel_id = $wheel->ID(); | |||||||||||||||||||||||||||
| 190 | 14 | $self->{wheels}->{ $wheel_id } = { wheel => $wheel, client => $client_id, tcp => 1 }; | |||||||||||||||||||||||||||
| 191 | 14 | $self->{clients}->{ $client_id } = { wheel => $wheel_id, client => $client }; | |||||||||||||||||||||||||||
| 192 | 14 | $kernel->sig_child( $wheel->PID(), '_sig_child' ); | |||||||||||||||||||||||||||
| 193 | 14 | return; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 14 | ▶ | sub _sig_child { | ||||||||||||||||||||||||||
|
Subroutine
_sig_child: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 197 | 14 | $poe_kernel->sig_handled(); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 11 | ▶ | sub _client_input { | ||||||||||||||||||||||||||
|
Subroutine
_client_input: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 201 | 11 | my ($kernel,$self,$data,$client_id) = @_[KERNEL,OBJECT,ARG0,ARG1]; | |||||||||||||||||||||||||||
| 202 | 11 | my $wheel_id = $self->{clients}->{ $client_id }->{wheel}; | |||||||||||||||||||||||||||
| 203 | 11 | ▶ | return unless $self->{wheels}->{ $wheel_id }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 11 | $self->{wheels}->{ $wheel_id }->{wheel}->put( $data ); | |||||||||||||||||||||||||||
| 205 | 11 | return; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 7 | ▶ | sub _client_error { | ||||||||||||||||||||||||||
|
Subroutine
_client_error: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 209 | 7 | my ($kernel,$self,$client_id) = @_[KERNEL,OBJECT,ARG3]; | |||||||||||||||||||||||||||
| 210 | 7 | my $wheel_id = $self->{clients}->{ $client_id }->{wheel}; | |||||||||||||||||||||||||||
| 211 | 7 | delete $self->{clients}->{ $client_id }; | |||||||||||||||||||||||||||
| 212 | 7 | ▶ | return unless $self->{wheels}->{ $wheel_id }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 7 | $self->{wheels}->{ $wheel_id }->{wheel}->shutdown_stdin(); | |||||||||||||||||||||||||||
| 214 | $self->{wheels}->{ $wheel_id }->{alarm} = | ||||||||||||||||||||||||||||
| 215 | 7 | ▶ | $kernel->delay_set( '_wheel_alarm', $self->{timeout} || 30, $wheel_id ); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'timeout'} || 30
MC/DC0%0/1
$self->{'timeout'} || 30
$self->{'timeout'}
Truth table50%1/2
A
A= $self->{'timeout'}
| |||||||||||||||||||||||||||||
| 216 | 7 | return; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 7 | ▶ | sub _client_flushed { | ||||||||||||||||||||||||||
|
Subroutine
_client_flushed: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||
| 220 | 7 | my ($kernel,$self,$client_id) = @_[KERNEL,OBJECT,ARG0]; | |||||||||||||||||||||||||||
| 221 | 7 | $self->{clients}->{ $client_id }->{pending} = 0; | |||||||||||||||||||||||||||
| 222 | 7 | ▶ | return unless $self->{clients}->{ $client_id }->{shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | delete $self->{clients}->{ $client_id }; | |||||||||||||||||||||||||||
| 224 | 0 | return; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 7 | ▶ | sub _wheel_out { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_out: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 228 | 7 | my ($kernel,$self,$data,$wheel_id) = @_[KERNEL,OBJECT,ARG0,ARG1]; | |||||||||||||||||||||||||||
| 229 | 7 | ▶ | if ( defined $self->{wheels}->{ $wheel_id }->{tcp} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 7 | my $client_id = $self->{wheels}->{ $wheel_id }->{client}; | |||||||||||||||||||||||||||
| 231 | 7 | ▶ | return unless $self->{clients}->{ $client_id }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 7 | $self->{clients}->{ $client_id }->{client}->put( $data ); | |||||||||||||||||||||||||||
| 233 | 7 | $self->{clients}->{ $client_id }->{pending} = 1; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | 7 | return; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub _wheel_alarm { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_alarm: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 239 | 0 | my ($kernel,$self,$wheel_id) = @_[KERNEL,OBJECT,ARG0]; | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | return unless $self->{wheels}->{ $wheel_id }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | $self->{wheels}->{ $wheel_id }->{wheel}->kill(9); | |||||||||||||||||||||||||||
| 242 | 0 | return; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 14 | ▶ | sub _wheel_close { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_close: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||
| 246 | 14 | my ($kernel,$self,$wheel_id) = @_[KERNEL,OBJECT,ARG0]; | |||||||||||||||||||||||||||
| 247 | 14 | my $wdata = delete $self->{wheels}->{ $wheel_id }; | |||||||||||||||||||||||||||
| 248 | 14 | ▶ | $kernel->alarm_remove( $wdata->{alarm} ) if $wdata->{alarm}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 14 | ▶ | if ( defined $wdata->{tcp} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 14 | my $client_id = $wdata->{client}; | |||||||||||||||||||||||||||
| 251 | 14 | ▶ | return unless $self->{clients}->{ $client_id }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 7 | ▶ | if ( $self->{clients}->{ $client_id }->{pending} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | $self->{clients}->{ $client_id }->{shutdown} = 1; | |||||||||||||||||||||||||||
| 254 | 0 | return; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 7 | delete $self->{clients}->{ $client_id }; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | 7 | return; | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 28 | ▶ | sub _wheel_error { | ||||||||||||||||||||||||||
|
Subroutine
_wheel_error: called CC=5 SCAR=27.0
| |||||||||||||||||||||||||||||
| 262 | 28 | my ($operation, $errnum, $errstr, $wheel_id) = @_[ARG0..ARG3]; | |||||||||||||||||||||||||||
| 263 | 28 | ▶ | return if $operation eq "read" and !$errnum; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$operation eq "read" and not $errnum
MC/DC0%0/2
$operation eq "read" and not $errnum
$operation eq "read"
not $errnum
Truth table33%1/3
A and not(B)
A= $operation eq "read"B= not $errnum
| |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | $errstr = "remote end closed" if $operation eq "read" and !$errnum; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$operation eq "read" and not $errnum
MC/DC0%0/2
$operation eq "read" and not $errnum
$operation eq "read"
not $errnum
Truth table0%0/3
A and not(B)
A= $operation eq "read"B= not $errnum
| |||||||||||||||||||||||||||||
| 265 | 0 | warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n"; | |||||||||||||||||||||||||||
| 266 | 0 | return; | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub _get_datagram { | ||||||||||||||||||||||||||
|
Subroutine
_get_datagram: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 5 | qq[Inet in'it]; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | __END__ | ||||||||||||||||||||||||||||