line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Server::SS::PreFork; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15531
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
536
|
use Net::Server::PreFork; |
|
1
|
|
|
|
|
55000
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
459
|
use Net::Server::Proto::TCP; |
|
1
|
|
|
|
|
1377
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
862
|
use Server::Starter qw(server_ports); |
|
1
|
|
|
|
|
6674
|
|
|
1
|
|
|
|
|
53
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Net::Server::PreFork); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
378
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.05; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub pre_bind { |
15
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
16
|
0
|
|
|
|
|
|
my $prop = $self->{server}; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my %ports = %{server_ports()}; |
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
for my $port (sort keys %ports) { |
20
|
0
|
|
|
|
|
|
my $sock = Net::Server::Proto::TCP->new(); |
21
|
0
|
0
|
|
|
|
|
if ($port =~ /^(.*):(.*?)$/) { |
22
|
0
|
|
|
|
|
|
$sock->NS_host($1); |
23
|
0
|
|
|
|
|
|
$sock->NS_port($2); |
24
|
|
|
|
|
|
|
} else { |
25
|
0
|
|
|
|
|
|
$sock->NS_host('*'); |
26
|
0
|
|
|
|
|
|
$sock->NS_port($port); |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
$sock->NS_proto('TCP'); |
29
|
0
|
0
|
|
|
|
|
$sock->fdopen($ports{$port}, 'r') |
30
|
|
|
|
|
|
|
or $self->fatal("failed to bind listening socket:$ports{$port}:$!"); |
31
|
0
|
|
|
|
|
|
push @{$prop->{sock}}, $sock; |
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
33
|
0
|
0
|
|
|
|
|
$prop->{multi_port} = 1 if @{$prop->{sock}} > 1; |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub bind { |
37
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
38
|
0
|
|
|
|
|
|
my $prop = $self->{server}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
### if more than one port we'll need to select on it |
41
|
0
|
0
|
0
|
|
|
|
if( @{ $prop->{port} } > 1 || $prop->{multi_port} ){ |
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$prop->{multi_port} = 1; |
43
|
0
|
|
|
|
|
|
$prop->{select} = IO::Select->new(); |
44
|
0
|
|
|
|
|
|
foreach ( @{ $prop->{sock} } ){ |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$prop->{select}->add( $_ ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
}else{ |
48
|
0
|
|
|
|
|
|
$prop->{multi_port} = undef; |
49
|
0
|
|
|
|
|
|
$prop->{select} = undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub sig_hup { |
54
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
$self->log( |
56
|
|
|
|
|
|
|
0, |
57
|
|
|
|
|
|
|
$self->log_time(), |
58
|
|
|
|
|
|
|
"Net::Server::SS::PreFork does not accept SIGHUP, send it to the" |
59
|
|
|
|
|
|
|
. " daemon!", |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub shutdown_sockets { |
64
|
|
|
|
|
|
|
# Net::Server::shutdown_sockets uses shutdown(2) to close accept(2)ing |
65
|
|
|
|
|
|
|
# sockets (which is a bug IMHO). On OSX, shutdown(2) returns ENOTSOCK |
66
|
|
|
|
|
|
|
# so the socket is not closed. On Linux, shutdown(2) closes the accepting |
67
|
|
|
|
|
|
|
# connection on all the forked processes sharing the socket (and the |
68
|
|
|
|
|
|
|
# next generation workers spawned by Server::Starter woul never be able |
69
|
|
|
|
|
|
|
# to accept incoming connections). Thus we override the function and use |
70
|
|
|
|
|
|
|
# close(2) instead of shutdown(2). |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my $prop = $self->{server}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
for my $sock (@{$prop->{sock}}) { |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$sock->close; # close sockets - nobody should be reading/writing still |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
### delete the sock objects |
79
|
0
|
|
|
|
|
|
$prop->{sock} = []; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
__END__ |