RPC/LogConnection.pm

filter: Statementstmt 100% 42 / 42 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 8 totaltotal 85.0% 57 / 67 CC 3 SCAR 2.4
CC
3
Cov
96%
input
2.0
disconnect
2.0
BEGIN
1.0
CRAP 1.3
« RPC/Message/Negotiate.pm ↑ Summary RPC/AuthPasswdHash.pm »
1 package Event::RPC::LogConnection;
2  
3 22 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 22 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 22 my $LOG_CONNECTION_ID;
11  
12 40 ▶sub get_cid { shift->{cid} }
Subroutine get_cid: called CC=1 SCAR=0.0
Pod undocumented
13 40 ▶sub get_sock { shift->{sock} }
Subroutine get_sock: called CC=1 SCAR=0.0
Pod undocumented
14 140 ▶sub get_server { shift->{server} }
Subroutine get_server: called CC=1 SCAR=0.0
Pod undocumented
15  
16 20 ▶sub get_watcher { shift->{watcher} }
Subroutine get_watcher: called CC=1 SCAR=0.0
Pod undocumented
17 20 ▶sub set_watcher { shift->{watcher} = $_[1] }
Subroutine set_watcher: called CC=1 SCAR=0.0
Pod undocumented
18  
19 sub new {
20 20 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
21 20 my ($server, $sock) = @_;
22  
23 20 my $cid = ++$LOG_CONNECTION_ID;
24  
25 20 my $self = bless {
26 cid => $cid,
27 sock => $sock,
28 server => $server,
29 watcher => undef,
30 }, $class;
31  
32 $self->{watcher} = $server->get_loop->add_io_watcher(
33 fh => $sock,
34 poll => 'r',
35 20 ▶ cb => sub { $self->input; 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 20 desc => "log reader $cid",
37 );
38  
39 20 $self->get_server->log (2,
40 "Got new logger connection. Connection ID is $cid"
41 );
42  
43 20 return $self;
44 }
45  
46 sub disconnect {
47 20 ▶ my $self = shift;
Subroutine disconnect: called CC=2 SCAR=6.9
Pod undocumented
48  
49 20 my $sock = $self->get_sock;
50 20 ▶ $self->get_server->get_logger->remove_fh($sock)
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_server->get_logger 0 20 20
51 if $self->get_server->get_logger;
52 20 $self->get_server->get_loop->del_io_watcher($self->get_watcher);
53 20 $self->set_watcher(undef);
54 20 close $sock;
55  
56 20 $self->get_server->set_log_clients_connected ( $self->get_server->get_log_clients_connected - 1 );
57 20 delete $self->get_server->get_logging_clients->{$self->get_cid};
58 20 $self->get_server->log(2, "Log client disconnected");
59  
60 20 1;
61 }
62  
63 sub input {
64 20 ▶ my $self = shift;
Subroutine input: called CC=2 SCAR=7.0
Pod undocumented
65  
66 20 my $buffer;
67 20 ▶ $self->disconnect
Branch: 1 branch
BranchTrueFalseTotal
unless sysread $self->get_sock, $buffer, 4096 20 0 20
68 if not sysread($self->get_sock, $buffer, 4096);
69  
70 20 1;
71 }
72  
73 22 1;
74  
75 __END__
« RPC/Message/Negotiate.pm ↑ Summary RPC/AuthPasswdHash.pm »