line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IRC::Indexer::Process::Trawler; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
## Handled by Trawl::Forking |
4
|
|
|
|
|
|
|
## Should be a proper session, really. |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89
|
|
7
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
72
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
12
|
use POE; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
26
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require IRC::Indexer::Trawl::Bot; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
935
|
use Storable qw/nfreeze thaw/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
133
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
10
|
use bytes; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub worker { |
18
|
0
|
0
|
|
0
|
0
|
|
$0 = "ircindexer TRAWL" unless $^O eq 'MSWin32'; |
19
|
|
|
|
|
|
|
## In case we're running as a forked coderef: |
20
|
0
|
|
|
|
|
|
POE::Kernel->stop; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
binmode STDOUT; |
23
|
0
|
|
|
|
|
|
binmode STDIN; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
STDOUT->autoflush(1); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $buf = ''; |
28
|
0
|
|
|
|
|
|
my $read_bytes; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
while (1) { |
31
|
0
|
0
|
|
|
|
|
if (defined $read_bytes) { |
|
|
0
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (length $buf >= $read_bytes) { |
33
|
0
|
|
|
|
|
|
my $inputref = thaw( substr($buf, 0, $read_bytes, "") ); |
34
|
0
|
|
|
|
|
|
$read_bytes = undef; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
## Note: $server here is the "target server" (ConnectedTo) |
37
|
|
|
|
|
|
|
## Not necessarily "Reported server name" (ServerName) |
38
|
|
|
|
|
|
|
## Same for reply to master. |
39
|
0
|
|
|
|
|
|
my ($server, $conf) = @$inputref; |
40
|
0
|
0
|
|
|
|
|
die "Process::Trawler passed invalid configuration" |
41
|
|
|
|
|
|
|
unless ref $conf eq 'HASH'; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
$0 = "ircindexer TRAWL $server" unless $^O eq 'MSWin32'; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $trawler = IRC::Indexer::Trawl::Bot->new(%$conf); |
46
|
0
|
|
|
|
|
|
$trawler->run(); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
POE::Kernel->run(); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $report; |
51
|
0
|
0
|
|
|
|
|
if ($trawler->failed) { |
52
|
0
|
|
|
|
|
|
$report = { |
53
|
|
|
|
|
|
|
NetName => $server, |
54
|
|
|
|
|
|
|
ServerName => $server, |
55
|
|
|
|
|
|
|
ConnectedTo => $server, |
56
|
|
|
|
|
|
|
FinishedAt => time, |
57
|
|
|
|
|
|
|
Status => 'FAIL', |
58
|
|
|
|
|
|
|
Failure => $trawler->failed, |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
$report = $trawler->report->netinfo(); |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $frozen = nfreeze([ $server, $report ]); |
65
|
0
|
|
|
|
|
|
my $stream = length($frozen) . chr(0) . $frozen ; |
66
|
0
|
|
|
|
|
|
my $written = syswrite(STDOUT, $stream); |
67
|
0
|
0
|
|
|
|
|
die $! unless $written == length $stream; |
68
|
0
|
|
|
|
|
|
exit 0 |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} elsif ($buf =~ s/^(\d+)\0//) { |
71
|
0
|
|
|
|
|
|
$read_bytes = $1; |
72
|
|
|
|
|
|
|
next |
73
|
0
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $readb = sysread(STDIN, $buf, 4096, length $buf); |
76
|
0
|
0
|
|
|
|
|
last unless $readb; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
exit 0 |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |