| 1 | package Sprocket::Server; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Sprocket qw( Base ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use base qw( Sprocket::Base ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use POE qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | Wheel::SocketFactory | ||||||||||||||||||||||||||||
| 10 | Filter::Stackable | ||||||||||||||||||||||||||||
| 11 | Filter::Stream | ||||||||||||||||||||||||||||
| 12 | Driver::SysRW | ||||||||||||||||||||||||||||
| 13 | 5 | ); | |||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Socket qw( INADDR_ANY inet_ntoa inet_aton AF_INET AF_UNIX PF_UNIX sockaddr_in ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Scalar::Util qw( dualvar ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | __PACKAGE__->mk_accessors( qw( listen_address listen_port ) ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 5 | $sprocket->register_hook( [qw( | |||||||||||||||||||||||||||
| 21 | sprocket.local.connection.accept | ||||||||||||||||||||||||||||
| 22 | sprocket.local.connection.reject | ||||||||||||||||||||||||||||
| 23 | sprocket.local.connection.receive | ||||||||||||||||||||||||||||
| 24 | sprocket.local.wheel.error | ||||||||||||||||||||||||||||
| 25 | )] ); | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | ▶ | sub spawn { | ||||||||||||||||||||||||||
|
Subroutine
spawn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | my $self = $class->SUPER::spawn( | |||||||||||||||||||||||||||
| 32 | $class->SUPER::new( | ||||||||||||||||||||||||||||
| 33 | @_, | ||||||||||||||||||||||||||||
| 34 | _type => 'local', | ||||||||||||||||||||||||||||
| 35 | ), | ||||||||||||||||||||||||||||
| 36 | qw( | ||||||||||||||||||||||||||||
| 37 | _startup | ||||||||||||||||||||||||||||
| 38 | _stop | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | local_accept | ||||||||||||||||||||||||||||
| 41 | local_receive | ||||||||||||||||||||||||||||
| 42 | local_flushed | ||||||||||||||||||||||||||||
| 43 | local_wheel_error | ||||||||||||||||||||||||||||
| 44 | local_error | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | accept | ||||||||||||||||||||||||||||
| 47 | reject | ||||||||||||||||||||||||||||
| 48 | ), | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 6 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | ▶ | sub check_params { | ||||||||||||||||||||||||||
|
Subroutine
check_params: called CC=9 SCAR=27.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6 | ▶ | $self->{name} ||= 'Server'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"name"} ||= "Server"
MC/DC0%0/1
$self->{"name"} ||= "Server"
$self->{"name"}
Truth table50%1/2
A
A= $self->{"name"}
| |||||||||||||||||||||||||||||
| 58 | 6 | ▶ | $self->{opts}->{listen_address} ||= INADDR_ANY; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"opts"}{"listen_address"} ||= "\0\0\0\0"
MC/DC0%0/1
$self->{"opts"}{"listen_address"} ||= "\0\0\0\0"
$self->{"opts"}{"listen_address"}
Truth table50%1/2
A
A= $self->{"opts"}{"listen_address"}
| |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | $self->{opts}->{domain} ||= AF_INET; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"opts"}{"domain"} ||= 2
MC/DC0%0/1
$self->{"opts"}{"domain"} ||= 2
$self->{"opts"}{"domain"}
Truth table50%1/2
A
A= $self->{"opts"}{"domain"}
| |||||||||||||||||||||||||||||
| 60 | $self->{opts}->{listen_port} = 0 | ||||||||||||||||||||||||||||
| 61 | 6 | ▶ | unless ( defined( $self->{opts}->{listen_port} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | $self->{opts}->{listen_queue} ||= 10000; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"opts"}{"listen_queue"} ||= 10000
MC/DC0%0/1
$self->{"opts"}{"listen_queue"} ||= 10000
$self->{"opts"}{"listen_queue"}
Truth table50%1/2
A
A= $self->{"opts"}{"listen_queue"}
| |||||||||||||||||||||||||||||
| 63 | 6 | ▶ | $self->{opts}->{reuse} ||= 'yes'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"opts"}{"reuse"} ||= "yes"
MC/DC0%0/1
$self->{"opts"}{"reuse"} ||= "yes"
$self->{"opts"}{"reuse"}
Truth table50%1/2
A
A= $self->{"opts"}{"reuse"}
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 6 | ▶ | if ( $self->{opts}->{ssl} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | eval 'use POE::Filter::SSL;'; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | die "During load of POE::Filter::SSL: $@\n"; | |||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||
| 70 | 0 | $self->_log( v => 2, msg => "SSL is ON for " | |||||||||||||||||||||||||||
| 71 | ."$self->{opts}->{listen_address}:$self->{opts}->{listen_port}"); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | return; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 6 | ▶ | sub _startup { | ||||||||||||||||||||||||||
|
Subroutine
_startup: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 79 | 6 | my $self = $_[ OBJECT ]; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # create a socket factory | ||||||||||||||||||||||||||||
| 82 | $self->{wheel} = POE::Wheel::SocketFactory->new( | ||||||||||||||||||||||||||||
| 83 | BindPort => $self->{opts}->{listen_port}, | ||||||||||||||||||||||||||||
| 84 | BindAddress => $self->{opts}->{listen_address}, | ||||||||||||||||||||||||||||
| 85 | SocketDomain => $self->{opts}->{domain}, | ||||||||||||||||||||||||||||
| 86 | Reuse => $self->{opts}->{reuse}, | ||||||||||||||||||||||||||||
| 87 | SuccessEvent => 'local_accept', | ||||||||||||||||||||||||||||
| 88 | FailureEvent => 'local_wheel_error', | ||||||||||||||||||||||||||||
| 89 | ListenQueue => $self->{opts}->{listen_queue}, | ||||||||||||||||||||||||||||
| 90 | 6 | ); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 6 | my ( $port, $ip ) = ( sockaddr_in( $self->{wheel}->getsockname() ) ); | |||||||||||||||||||||||||||
| 93 | 6 | $ip = inet_ntoa( $ip ); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 6 | ▶ | $self->listen_port( $self->{opts}->{listen_port} || $port ); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'opts'}{'listen_port'} || $port
MC/DC0%0/2
$self->{'opts'}{'listen_port'} || $port
$self->{'opts'}{'listen_port'}
$port
Truth table66%2/3
A || B
A= $self->{'opts'}{'listen_port'}B= $port
| |||||||||||||||||||||||||||||
| 96 | 6 | ▶ | $self->listen_address( $ip || $self->{opts}->{listen_address} ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$ip || $self->{'opts'}{'listen_address'}
MC/DC0%0/2
$ip || $self->{'opts'}{'listen_address'}
$ip
$self->{'opts'}{'listen_address'}
Truth table33%1/3
A || B
A= $ipB= $self->{'opts'}{'listen_address'}
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | $self->_log( v => 2, msg => sprintf( "Listening to port %d(%d) on %s(%s)", | ||||||||||||||||||||||||||||
| 99 | $self->{opts}->{listen_port}, $self->listen_port, | ||||||||||||||||||||||||||||
| 100 | 6 | $self->{opts}->{listen_address}, $self->listen_address ) ); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 6 | ▶ | sub _stop { | ||||||||||||||||||||||||||
|
Subroutine
_stop: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 6 | my $self = $_[ OBJECT ]; | |||||||||||||||||||||||||||
| 105 | 6 | $self->_log( v => 2, msg => $self->{name}." stopped."); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Accept a new connection | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | ▶ | sub local_accept { | ||||||||||||||||||||||||||
|
Subroutine
local_accept: called CC=2 SCAR=7.3
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 4 | my ( $self, $socket, $peer_ip, $peer_port ) = | |||||||||||||||||||||||||||
| 112 | @_[ OBJECT, ARG0, ARG1, ARG2 ]; | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 4 | my ( $port, $ip ); | |||||||||||||||||||||||||||
| 115 | 4 | ▶ | if ( length( $peer_ip ) == 4 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 4 | ( $port, $ip ) = ( sockaddr_in( getsockname( $socket ) ) ); | |||||||||||||||||||||||||||
| 117 | 4 | $peer_ip = inet_ntoa( $peer_ip ); | |||||||||||||||||||||||||||
| 118 | 4 | $ip = inet_ntoa( $ip ); | |||||||||||||||||||||||||||
| 119 | } else { | ||||||||||||||||||||||||||||
| 120 | # ipv6 | ||||||||||||||||||||||||||||
| 121 | 0 | ( $port, $ip ) = ( Socket6::sockaddr_in6( getsockname( $socket ) ) ); | |||||||||||||||||||||||||||
| 122 | 0 | $peer_ip = Socket6::inet_ntop( $self->{opts}->{domain}, $peer_ip ); | |||||||||||||||||||||||||||
| 123 | 0 | $ip = Socket6::inet_ntop( $self->{opts}->{domain}, $ip ); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 4 | my $con = $self->new_connection( | |||||||||||||||||||||||||||
| 127 | local_ip => $ip, | ||||||||||||||||||||||||||||
| 128 | local_port => $port, | ||||||||||||||||||||||||||||
| 129 | peer_ip => $peer_ip, | ||||||||||||||||||||||||||||
| 130 | # TODO resolve these? | ||||||||||||||||||||||||||||
| 131 | peer_hostname => $peer_ip, | ||||||||||||||||||||||||||||
| 132 | peer_port => $peer_port, | ||||||||||||||||||||||||||||
| 133 | peer_addr => "$peer_ip:$peer_port", | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 4 | $con->socket( $socket ); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 4 | $self->process_plugins( [ 'local_accept', $self, $con, $socket ] ); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 4 | return; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 4 | ▶ | sub accept { | ||||||||||||||||||||||||||
|
Subroutine
accept: called CC=11 SCAR=34.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 4 | my ( $self, $con, $opts ) = @_[ OBJECT, HEAP, ARG0 ]; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 4 | ▶ | $opts = {} unless ( $opts ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 4 | ▶ | $opts->{block_size} ||= 2048; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{"block_size"} ||= 2048
MC/DC0%0/1
$opts->{"block_size"} ||= 2048
$opts->{"block_size"}
Truth table50%1/2
A
A= $opts->{"block_size"}
| |||||||||||||||||||||||||||||
| 149 | 4 | ▶ | $opts->{filter} ||= POE::Filter::Stackable->new( | ||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{"filter"} ||= "POE::Filter::Stackable"->new("Filters", ["POE::Filter::Stream"->new])
MC/DC0%0/2
$opts->{"filter"} ||= "POE::Filter::Stackable"->new("Filters", ["POE::Filter::Stream"->new])
$opts->{"filter"}
"POE::Filter::Stackable"->new("Filters", ["POE::Filter::Stream"->new])
Truth table33%1/3
A ||= B
A= $opts->{"filter"}B= "POE::Filter::Stackable"->new("Filters", ["POE::Filter::Stream"->new])
| |||||||||||||||||||||||||||||
| 150 | Filters => [ | ||||||||||||||||||||||||||||
| 151 | POE::Filter::Stream->new(), | ||||||||||||||||||||||||||||
| 152 | ] | ||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||
| 154 | $opts->{time_out} = $self->{opts}->{time_out} | ||||||||||||||||||||||||||||
| 155 | 4 | ▶ | unless( defined( $opts->{time_out} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 4 | ▶ | if ( $self->{opts}->{ssl} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ( $opts->{filter}->isa( 'POE::Filter::Stackable' ) || $opts->{filter}->can( 'push' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->{"filter"}->isa("POE::Filter::Stackable") or $opts->{"filter"}->can("push")
MC/DC0%0/2
$opts->{"filter"}->isa("POE::Filter::Stackable") or $opts->{"filter"}->can("push")
$opts->{"filter"}->isa("POE::Filter::Stackable")
$opts->{"filter"}->can("push")
Truth table0%0/3
A or B
A= $opts->{"filter"}->isa("POE::Filter::Stackable")B= $opts->{"filter"}->can("push")
| |||||||||||||||||||||||||||||
| 159 | # TODO use filter push | ||||||||||||||||||||||||||||
| 160 | 0 | eval { | |||||||||||||||||||||||||||
| 161 | $opts->{filter} = POE::Filter::Stackable->new( | ||||||||||||||||||||||||||||
| 162 | Filters => [ | ||||||||||||||||||||||||||||
| 163 | POE::Filter::SSL->new( | ||||||||||||||||||||||||||||
| 164 | key_file => $self->{opts}->{ssl_key_file}, | ||||||||||||||||||||||||||||
| 165 | cert_file => $self->{opts}->{ssl_cert_file} | ||||||||||||||||||||||||||||
| 166 | ) | ||||||||||||||||||||||||||||
| 167 | 0 | ] | |||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||
| 169 | }; | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | $self->_log( v => 1, msg => "Could not push POE::Filter::SSL on the stack, REJECTING CONNECTION : $@"); | |||||||||||||||||||||||||||
| 172 | 0 | $con->close( 1 ); | |||||||||||||||||||||||||||
| 173 | 0 | return; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 0 | $self->_log( v => 4, msg => "Using SSL"); | |||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | 0 | $self->_log( v => 1, msg => "The filter: $opts->{filter} does not have a push method, or isn't a Stackable Filter. REJECTING CONNECTION"); | |||||||||||||||||||||||||||
| 178 | 0 | $con->close( 1 ); | |||||||||||||||||||||||||||
| 179 | 0 | return; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 4 | my $socket = $con->socket; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | $con->wheel_readwrite( | ||||||||||||||||||||||||||||
| 186 | Handle => $socket, | ||||||||||||||||||||||||||||
| 187 | Driver => POE::Driver::SysRW->new( BlockSize => $opts->{block_size} ), | ||||||||||||||||||||||||||||
| 188 | Filter => $opts->{filter}, | ||||||||||||||||||||||||||||
| 189 | 4 | InputEvent => $con->event( 'local_receive' ), | |||||||||||||||||||||||||||
| 190 | ErrorEvent => $con->event( 'local_error' ), | ||||||||||||||||||||||||||||
| 191 | FlushedEvent => $con->event( 'local_flushed' ), | ||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | $con->set_time_out( $opts->{time_out} ) | ||||||||||||||||||||||||||||
| 195 | 4 | ▶ | if ( $opts->{time_out} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 4 | $sprocket->broadcast( 'sprocket.local.connection.accept', { | |||||||||||||||||||||||||||
| 198 | source => $self, | ||||||||||||||||||||||||||||
| 199 | target => $con, | ||||||||||||||||||||||||||||
| 200 | } ); | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 4 | $con->socket( undef ); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 4 | $self->process_plugins( [ 'local_connected', $self, $con, $socket ] ); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # nothing took the connection | ||||||||||||||||||||||||||||
| 207 | 4 | ▶ | unless ( $con->plugin ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | $self->_log( v => 2, msg => "No plugin took this connection, Dropping."); | |||||||||||||||||||||||||||
| 209 | 0 | $con->close(); | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 4 | return; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub reject { | ||||||||||||||||||||||||||
|
Subroutine
reject: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 216 | 0 | my ( $self, $con ) = @_[ OBJECT, HEAP ]; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | $sprocket->broadcast( 'sprocket.remote.connection.reject', { | |||||||||||||||||||||||||||
| 219 | source => $self, | ||||||||||||||||||||||||||||
| 220 | target => $con, | ||||||||||||||||||||||||||||
| 221 | } ); | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # XXX other? | ||||||||||||||||||||||||||||
| 224 | 0 | $con->socket( undef ); | |||||||||||||||||||||||||||
| 225 | 0 | $con->close( 1 ); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | return; | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 5 | ▶ | sub local_receive { | ||||||||||||||||||||||||||
|
Subroutine
local_receive: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | 5 | my ( $self, $con ) = @_[ OBJECT, HEAP ]; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 5 | $sprocket->broadcast( 'sprocket.local.connection.receive', { | |||||||||||||||||||||||||||
| 234 | source => $self, | ||||||||||||||||||||||||||||
| 235 | target => $con, | ||||||||||||||||||||||||||||
| 236 | data => $_[ARG0] | ||||||||||||||||||||||||||||
| 237 | } ); | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 5 | $self->process_plugins( [ 'local_receive', $self, $con, $_[ARG0] ] ); | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 5 | return; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 6 | ▶ | sub local_flushed { | ||||||||||||||||||||||||||
|
Subroutine
local_flushed: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 245 | 6 | my ( $self, $con ) = @_[ OBJECT, HEAP ]; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 6 | ▶ | $con->close() | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$con->close_on_flush and not $con->get_driver_out_octets
MC/DC0%0/2
$con->close_on_flush and not $con->get_driver_out_octets
$con->close_on_flush
not $con->get_driver_out_octets
Truth table33%1/3
A and not(B)
A= $con->close_on_flushB= not $con->get_driver_out_octets
| |||||||||||||||||||||||||||||
| 248 | if ( $con->close_on_flush && not $con->get_driver_out_octets() ); | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # If you need this event in your plugin, subclass Sprocket::Server | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 6 | return; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 1 | ▶ | sub local_wheel_error { | ||||||||||||||||||||||||||
|
Subroutine
local_wheel_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 256 | 1 | my ( $self, $operation, $errnum, $errstr ) = | |||||||||||||||||||||||||||
| 257 | @_[ OBJECT, ARG0, ARG1, ARG2 ]; | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 1 | $self->_log( v => 1, msg => $self->{name}." encountered $operation error $errnum: $errstr (Server socket wheel)"); | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 1 | $sprocket->broadcast( 'sprocket.local.wheel.error', { | |||||||||||||||||||||||||||
| 262 | source => $self, | ||||||||||||||||||||||||||||
| 263 | operation => $operation, | ||||||||||||||||||||||||||||
| 264 | errnum => $errnum, | ||||||||||||||||||||||||||||
| 265 | errstr => $errstr, | ||||||||||||||||||||||||||||
| 266 | } ); | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 1 | $self->process_plugins( [ 'local_error', $self, $operation, $errnum, $errstr ] ); | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 1 | return; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 1 | ▶ | sub local_error { | ||||||||||||||||||||||||||
|
Subroutine
local_error: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 274 | 1 | my ( $self, $con, $operation, $errnum, $errstr ) = | |||||||||||||||||||||||||||
| 275 | @_[ OBJECT, HEAP, ARG0, ARG1, ARG2 ]; | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 1 | $con->error( dualvar( $errnum, "$operation - $errstr" ) ); | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | # TODO use constant | ||||||||||||||||||||||||||||
| 280 | 1 | ▶ | $self->_log( v => 3, msg => $self->{name}." encountered $operation error $errnum: $errstr") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | if ( $errnum != 0 ); | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 1 | $self->process_plugins( [ 'local_disconnected', $self, $con, 1, $operation, $errnum, $errstr ] ); | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 1 | $con->close(); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 1 | return; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 1 | ▶ | sub begin_soft_shutdown { | ||||||||||||||||||||||||||
|
Subroutine
begin_soft_shutdown: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 291 | 1 | my $self = $_[ OBJECT ]; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 1 | $self->_log( v => 2, msg => $self->{name}." is shuting down (soft)"); | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 1 | foreach ( values %{$self->{heaps}} ) { | |||||||||||||||||||||||||||
| 296 | 1 | ▶ | next unless defined; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 1 | $self->process_plugins( [ 'local_shutdown', $self, $_ ] ); | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 1 | return; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 5 | 1; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | __END__ | ||||||||||||||||||||||||||||