line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Signalet; |
2
|
4
|
|
|
4
|
|
1444
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
113
|
|
3
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
140
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.02; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
21
|
use Carp (); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
64
|
|
7
|
4
|
|
|
4
|
|
3800
|
use IO::Socket::INET; |
|
4
|
|
|
|
|
88101
|
|
|
4
|
|
|
|
|
33
|
|
8
|
4
|
|
|
4
|
|
6739
|
use Net::IP::Minimal qw(ip_is_ipv4); |
|
4
|
|
|
|
|
3315
|
|
|
4
|
|
|
|
|
1678
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _init { |
12
|
4
|
|
|
4
|
|
47
|
my ($class, %args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
|
|
48
|
for (qw(saddr daddr)) { |
15
|
8
|
100
|
|
|
|
554
|
if (exists $args{$_}) { |
16
|
6
|
50
|
|
|
|
79
|
ip_is_ipv4 $args{$_} |
17
|
|
|
|
|
|
|
or Carp::croak "$_ is not ipv4: $args{$_}"; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub recv { |
23
|
1
|
|
|
1
|
0
|
28
|
my ($self) = @_; |
24
|
1
|
50
|
|
|
|
14
|
unless ($self->{sock}) { |
25
|
0
|
|
|
|
|
0
|
Carp::croak "recv: Not connect"; |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
148
|
my $message = $self->{sock}->getline; |
28
|
1
|
|
|
|
|
188
|
chomp $message; |
29
|
1
|
|
|
|
|
4
|
return $message; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub send { |
33
|
1
|
|
|
1
|
0
|
30
|
my ($self, $message) = @_; |
34
|
1
|
50
|
|
|
|
11
|
unless ($self->{sock}) { |
35
|
0
|
|
|
|
|
0
|
Carp::croak "send: Not connect"; |
36
|
|
|
|
|
|
|
} |
37
|
1
|
|
|
|
|
35
|
$self->{sock}->print($message."\n"); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub run { |
41
|
0
|
|
|
0
|
0
|
0
|
my ($self, %params) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
0
|
|
|
0
|
if (!exists $params{command} && !exists $params{code}) { |
44
|
0
|
|
|
|
|
0
|
Carp::croak "Required command or code"; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
0
|
my $pid = fork; |
47
|
0
|
0
|
|
|
|
0
|
unless ($pid) { |
48
|
|
|
|
|
|
|
# child process |
49
|
0
|
0
|
|
|
|
0
|
if (my $command = $params{command}) { |
|
|
0
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
if (ref($params{command}) eq 'ARRAY') { |
51
|
0
|
|
|
|
|
0
|
exec @{$params{command}}; |
|
0
|
|
|
|
|
0
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
0
|
exec $command; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($params{code}) { |
58
|
0
|
|
|
|
|
0
|
$params{code}->(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
0
|
0
|
|
|
|
0
|
$self->{worker_pid} = $pid if $pid > 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub term_worker { |
65
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
66
|
0
|
|
|
|
|
0
|
my $pgrp = getpgrp $self->{worker_pid}; |
67
|
0
|
|
|
|
|
0
|
kill(-15, $pgrp); # send TERM signal to child processes |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub close { |
71
|
2
|
|
|
2
|
0
|
7394
|
my ($self) = @_; |
72
|
2
|
|
|
|
|
454
|
close $self->{sock}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
__END__ |