Perlbal/UploadListener.pm

filter: Statementstmt 30.9% 17 / 55 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 45.4% 5 / 11 Podpod 50.0% 3 / 6 totaltotal 27.1% 25 / 92 CC 8 SCAR 28.2
CC
8
Cov
24%
event_read
42.0
new
12.0
get_status
2.0
CRAP 16.7
« Perlbal/ClientProxy.pm ↑ Summary Perlbal/HTTPHeaders.pm »
1 ######################################################################
2 # Listen for UDP upload status packets
3 #
4 # Copyright 2005-2007, Six Apart, Ltd.
5  
6  
7 package Perlbal::UploadListener;
8 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶no warnings qw(deprecated);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 22 ▶use base "Perlbal::Socket";
Subroutine BEGIN: called CC=1 SCAR=0.0
13 22 ▶use fields qw(service hostport);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # TCPListener
16 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
17 0 my ($class, $hostport, $service) = @_;
18  
19 0 my $sock =
20 IO::Socket::INET->new(
21 LocalAddr => $hostport,
22 Proto => "udp",
23 ReuseAddr => 1,
24 Blocking => 0,
25 );
26  
27 0 ▶ return Perlbal::error("Error creating listening socket: " . ($@ || $!))
Branch: 1 branch
BranchTrueFalseTotal
unless $sock 0 0 0
Condition0%0/3
$@ || $!
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ || $!
$@ $!
Truth table0%0/3
A || B
A= $@B= $!
ABresult
1X1
011
000
28 unless $sock;
29 0 my $self = fields::new($class);
30 0 $self->SUPER::new($sock);
31 0 $self->{service} = $service;
32 0 $self->{hostport} = $hostport;
33 0 $self->watch_read(1);
34 0 return $self;
35 }
36  
37 22 my %status;
38 my @todelete;
39  
40 0 ▶sub get_status {
Subroutine get_status: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my $ses = shift;
42 0 return $status{$ses};
43 }
44  
45 # TCPListener: accepts a new client connection
46 0 ▶sub event_read {
Subroutine event_read: not called CC=6 SCAR=37.4
Pod documented
47 0 my Perlbal::TCPListener $self = shift;
48  
49 0 my $buf;
50 0 $self->{sock}->recv($buf, 500);
51 0 ▶ return unless $buf =~ /^UPLOAD:(\w{5,50}):(\d+):(\d+):(\d+):(\d+)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $buf =~ /^UPLOAD:(\w{5,50}):(\d+):(\d+):(\d+):(\d+)$/ 0 0 0
52 0 my ($ses, $done, $total, $starttime, $nowtime) = ($1, $2, $3, $4, $5);
53  
54 0 my $now = time();
55  
56 0 $status{$ses} = {
57 done => $done,
58 total => $total,
59 starttime => $starttime,
60 lasttouch => $now,
61 };
62  
63 # keep a history of touched records, then we'll clean 'em
64 # after 30 seconds.
65 0 push @todelete, [$now, $ses];
66 0 my $too_old = $now - 4;
67 0 ▶ while (@todelete && $todelete[0][0] < $too_old) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todelete and $todelete[0][0] < $too_old) 0 0 0
Condition0%0/3
@todelete and $todelete[0][0] < $too_old
!ll&&!rl&&r
000
MC/DC0%0/2
@todelete and $todelete[0][0] < $too_old
@todelete $todelete[0][0] < $too_old
Truth table0%0/3
A and B
A= @todeleteB= $todelete[0][0] < $too_old
ABresult
0X0
100
111
68 0 my $rec = shift @todelete;
69 0 my $to_kill = $rec->[1];
70 0 ▶ if (my $krec = $status{$to_kill}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $krec = $status{$to_kill}) 0 0 0
71 0 my $last_touch = $krec->{lasttouch};
72 0 ▶ delete $status{$to_kill} if $last_touch < $too_old;
Branch: 1 branch
BranchTrueFalseTotal
if $last_touch < $too_old 0 0 0
73 }
74 }
75 }
76  
77 0 ▶sub as_string {
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
78 0 my Perlbal::TCPListener $self = shift;
79 0 my $ret = $self->SUPER::as_string;
80 0 my Perlbal::Service $svc = $self->{service};
81 0 $ret .= ": listening on $self->{hostport} for service '$svc->{name}'";
82 0 return $ret;
83 }
84  
85 0 ▶sub as_string_html {
Subroutine as_string_html: not called CC=1 SCAR=6.9
Pod undocumented
86 0 my Perlbal::TCPListener $self = shift;
87 0 my $ret = $self->SUPER::as_string_html;
88 0 my Perlbal::Service $svc = $self->{service};
89 0 $ret .= ": listening on $self->{hostport} for service <b>$svc->{name}</b>";
90 0 return $ret;
91 }
92  
93 0 ▶sub die_gracefully {
Subroutine die_gracefully: not called CC=1 SCAR=6.9
Pod undocumented
94 # die off so we stop waiting for new connections
95 0 my $self = shift;
96 0 $self->close('graceful_death');
97 }
98  
99  
100 22 1;
101  
102  
103 # Local Variables:
104 # mode: perl
105 # c-basic-indent: 4
106 # indent-tabs-mode: nil
107 # End:
« Perlbal/ClientProxy.pm ↑ Summary Perlbal/HTTPHeaders.pm »