line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Event::RPC::LogConnection; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
4
|
1
|
|
|
1
|
|
1143
|
use Socket; |
|
1
|
|
|
|
|
9611
|
|
|
1
|
|
|
|
|
2745
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $LOG_CONNECTION_ID; |
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
0
|
|
sub get_cid { shift->{cid} } |
9
|
0
|
|
|
0
|
0
|
|
sub get_sock { shift->{sock} } |
10
|
0
|
|
|
0
|
0
|
|
sub get_server { shift->{server} } |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
0
|
0
|
|
sub get_watcher { shift->{watcher} } |
13
|
0
|
|
|
0
|
0
|
|
sub set_watcher { shift->{watcher} = $_[1] } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
17
|
0
|
|
|
|
|
|
my ($server, $sock) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $cid = ++$LOG_CONNECTION_ID; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $self = bless { |
22
|
|
|
|
|
|
|
cid => $cid, |
23
|
|
|
|
|
|
|
sock => $sock, |
24
|
|
|
|
|
|
|
server => $server, |
25
|
|
|
|
|
|
|
watcher => undef, |
26
|
|
|
|
|
|
|
}, $class; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$self->{watcher} = $server->get_loop->add_io_watcher( |
29
|
|
|
|
|
|
|
fh => $sock, |
30
|
|
|
|
|
|
|
poll => 'r', |
31
|
0
|
|
|
0
|
|
|
cb => sub { $self->input; 1 }, |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
desc => "log reader $cid", |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$self->get_server->log (2, |
36
|
|
|
|
|
|
|
"Got new logger connection. Connection ID is $cid" |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub disconnect { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $sock = $self->get_sock; |
46
|
0
|
0
|
|
|
|
|
$self->get_server->get_logger->remove_fh($sock) |
47
|
|
|
|
|
|
|
if $self->get_server->get_logger; |
48
|
0
|
|
|
|
|
|
$self->get_server->get_loop->del_io_watcher($self->get_watcher); |
49
|
0
|
|
|
|
|
|
$self->set_watcher(undef); |
50
|
0
|
|
|
|
|
|
close $sock; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->get_server->set_log_clients_connected ( $self->get_server->get_log_clients_connected - 1 ); |
53
|
0
|
|
|
|
|
|
delete $self->get_server->get_logging_clients->{$self->get_cid}; |
54
|
0
|
|
|
|
|
|
$self->get_server->log(2, "Log client disconnected"); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub input { |
60
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $buffer; |
63
|
0
|
0
|
|
|
|
|
$self->disconnect |
64
|
|
|
|
|
|
|
if not sysread($self->get_sock, $buffer, 4096); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |