Server/Listener.pm

filter: Statementstmt 42.5% 23 / 54 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 37.6% 32 / 85 CC 9 SCAR 28.4
CC
9
Cov
32%
new
30.0
event_read
30.0
__ANON__
2.0
CRAP 17.2
« Server.pm ↑ Summary Server/Job.pm »
1 package Gearman::Server::Listener;
2 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Gearman::Server::Listener::VERSION = qv("v1.130.1");
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base 'Danga::Socket';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use fields qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
10 server
11 accept_per_loop
12 1 /;
13  
14 1 ▶use Errno qw(EAGAIN);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Socket qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
16 IPPROTO_TCP
17 TCP_NODELAY
18 SOL_SOCKET
19 SO_ERROR
20 1 /;
21  
22 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
23 0 my Gearman::Server::Listener $self = shift;
24 0 my $sock = shift;
25 0 my $server = shift;
26  
27 0 my %opts = @_;
28  
29 0 my $accept_per_loop = delete $opts{accept_per_loop};
30  
31 0 ▶ warn "Extra options passed into new: " . join(', ', keys %opts) . "\n"
Branch: 1 branch
BranchTrueFalseTotal
if keys %opts 0 0 0
32 if keys %opts;
33  
34 0 ▶ $accept_per_loop = 10
Branch: 1 branch
BranchTrueFalseTotal
unless defined $accept_per_loop and $accept_per_loop >= 1 0 0 0
Condition0%0/3
defined $accept_per_loop and $accept_per_loop >= 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $accept_per_loop and $accept_per_loop >= 1
defined $accept_per_loop $accept_per_loop >= 1
Truth table0%0/3
A and B
A= defined $accept_per_loopB= $accept_per_loop >= 1
ABresult
0X0
100
111
35 unless defined $accept_per_loop and $accept_per_loop >= 1;
36  
37 0 ▶ $self = fields::new($self) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
38  
39 # make sure provided listening socket is non-blocking
40 0 IO::Handle::blocking($sock, 0);
41  
42 0 $self->SUPER::new($sock);
43  
44 0 $self->{server} = $server;
45 0 $self->{accept_per_loop} = int($accept_per_loop);
46  
47 0 $self->watch_read(1);
48  
49 0 return $self;
50 } ## end sub new
51  
52 0 ▶sub event_read {
Subroutine event_read: not called CC=5 SCAR=34.0
Pod documented
53 0 my Gearman::Server::Listener $self = shift;
54  
55 0 my $listen_sock = $self->sock;
56  
57 0 local $!;
58 0 local $SIG{PIPE} = "IGNORE";
59  
60 0 my $remaining = $self->{accept_per_loop};
61  
62 0 ▶ while (my $csock = $listen_sock->accept) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $csock = $listen_sock->accept) 0 0 0
63 0 IO::Handle::blocking($csock, 0);
64 0 ▶ setsockopt($csock, IPPROTO_TCP, TCP_NODELAY, pack("l", 1)) or die;
Branch: 1 branch
BranchTrueFalseTotal
setsockopt $csock, 6, 1, "\1\0\0\0" or die 0 0 0
65  
66 0 my $server = $self->{server};
67  
68 0 $server->debug(
69 sprintf("Listen child making a Client for %d.", fileno($csock)));
70 0 $server->new_client($csock);
71 0 ▶ return unless $remaining-- > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $remaining-- > 0 0 0 0
72 } ## end while (my $csock = $listen_sock...)
73  
74 0 ▶ return if $! == EAGAIN;
Branch: 1 branch
BranchTrueFalseTotal
if $! == 11 0 0 0
75  
76 0 warn "Error accepting incoming connection: $!\n";
77  
78 0 $self->watch_read(0);
79  
80 Danga::Socket->AddTimer(
81 .1,
82 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 $self->watch_read(1);
84 }
85 0 );
86 } ## end sub event_read
87  
88 1 1;
« Server.pm ↑ Summary Server/Job.pm »