| 1 | package Gearman::Server::Listener; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use version (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | $Gearman::Server::Listener::VERSION = version->declare("1.140_001"); | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Gearman::Server::Listener - a listener for L<Gearman::Server> | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Based on L<Danga::Socket> | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use base 'Danga::Socket'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use fields qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | server | ||||||||||||||||||||||||||||
| 21 | accept_per_loop | ||||||||||||||||||||||||||||
| 22 | 3 | /; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use Errno qw(EAGAIN); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use Socket qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | IPPROTO_TCP | ||||||||||||||||||||||||||||
| 27 | TCP_NODELAY | ||||||||||||||||||||||||||||
| 28 | SOL_SOCKET | ||||||||||||||||||||||||||||
| 29 | SO_ERROR | ||||||||||||||||||||||||||||
| 30 | 3 | /; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 METHODS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||
| 35 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 7 | my Gearman::Server::Listener $self = shift; | |||||||||||||||||||||||||||
| 37 | 7 | my $sock = shift; | |||||||||||||||||||||||||||
| 38 | 7 | my $server = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 7 | my %opts = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 7 | my $accept_per_loop = delete $opts{accept_per_loop}; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 7 | ▶ | warn "Extra options passed into new: " . join(', ', keys %opts) . "\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if keys %opts; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 7 | ▶ | $accept_per_loop = 10 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $accept_per_loop and $accept_per_loop >= 1
MC/DC0%0/2
defined $accept_per_loop and $accept_per_loop >= 1
defined $accept_per_loop
$accept_per_loop >= 1
Truth table33%1/3
A and B
A= defined $accept_per_loopB= $accept_per_loop >= 1
| |||||||||||||||||||||||||||||
| 48 | unless defined $accept_per_loop and $accept_per_loop >= 1; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | ▶ | $self = fields::new($self) unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # make sure provided listening socket is non-blocking | ||||||||||||||||||||||||||||
| 53 | 7 | IO::Handle::blocking($sock, 0); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 7 | $self->SUPER::new($sock); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 7 | $self->{server} = $server; | |||||||||||||||||||||||||||
| 58 | 7 | $self->{accept_per_loop} = int($accept_per_loop); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 7 | $self->watch_read(1); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 7 | return $self; | |||||||||||||||||||||||||||
| 63 | } ## end sub new | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head2 event_read() | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | wait for connection | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub event_read { | ||||||||||||||||||||||||||
|
Subroutine
event_read: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | my Gearman::Server::Listener $self = shift; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my $listen_sock = $self->sock; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | local $!; | |||||||||||||||||||||||||||
| 76 | 0 | local $SIG{PIPE} = "IGNORE"; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | my $remaining = $self->{accept_per_loop}; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | while (my $csock = $listen_sock->accept) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | IO::Handle::blocking($csock, 0); | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | setsockopt($csock, IPPROTO_TCP, TCP_NODELAY, pack("l", 1)) or die; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my $server = $self->{server}; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $server->debug( | |||||||||||||||||||||||||||
| 87 | sprintf("Listen child making a Client for %d.", fileno($csock))); | ||||||||||||||||||||||||||||
| 88 | 0 | $server->new_client($csock); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | return unless $remaining-- > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | } ## end while (my $csock = $listen_sock...) | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return if $! == EAGAIN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | warn "Error accepting incoming connection: $!\n"; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | $self->watch_read(0); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | Danga::Socket->AddTimer( | ||||||||||||||||||||||||||||
| 99 | .1, | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 101 | 0 | $self->watch_read(1); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | ); | |||||||||||||||||||||||||||
| 104 | } ## end sub event_read | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 3 | 1; | |||||||||||||||||||||||||||