| 1 | package Eixo::Queue::SocketPair; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Eixo::Base::Clase qw(Eixo::QueueInmediate); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Socket; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use IO::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use IO::Select; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Eixo::Queue::Job; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Eixo::Queue::SocketPairDriver; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | has( | |||||||||
| 15 | |||||||||||
| 16 | backend=>undef, | ||||||||||
| 17 | |||||||||||
| 18 | pid_c=>undef, | ||||||||||
| 19 | |||||||||||
| 20 | initiated=>undef, | ||||||||||
| 21 | |||||||||||
| 22 | jobSent=>undef, | ||||||||||
| 23 | |||||||||||
| 24 | input=>undef, | ||||||||||
| 25 | |||||||||||
| 26 | output=>undef, | ||||||||||
| 27 | |||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub init{ | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | 1 | my ($self) = @_; | |||||||||
| 32 | |||||||||||
| 33 | 1 | my ($driver) = $self->__openCommunications; | |||||||||
| 34 | |||||||||||
| 35 | 1 | $self->__startBackend($driver); | |||||||||
| 36 | |||||||||||
| 37 | 1 | $self->initiated(1); | |||||||||
| 38 | |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 1 | ▶ | sub DESTROY{ | ||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.0
| |||||||||||
| 42 | 1 | my ($self) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | if($self->pid_c){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 1 | kill(10, $self->pid_c); | |||||||||
| 47 | |||||||||||
| 48 | 1 | waitpid($self->pid_c, 0); | |||||||||
| 49 | |||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | 3 | ▶ | sub __openCommunications{ | ||||||||
|
Subroutine
__openCommunications: called CC=1 SCAR=0.0
| |||||||||||
| 56 | 3 | my ($self) = @_; | |||||||||
| 57 | |||||||||||
| 58 | 3 | &Eixo::Queue::SocketPairDriver::open(); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | ▶ | sub __startBackend{ | ||||||||
|
Subroutine
__startBackend: called CC=3 SCAR=14.5
| |||||||||||
| 62 | 1 | my ($self, $driver) = @_; | |||||||||
| 63 | |||||||||||
| 64 | 1 | my ($a, $b) = ($self->__openCommunications(), $self->__openCommunications); | |||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | if(my $pid = fork){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | 1 | $a->A; | |||||||||
| 70 | 1 | $b->A; | |||||||||
| 71 | |||||||||||
| 72 | 1 | $self->{input} = $a; | |||||||||
| 73 | 1 | $self->{output} = $b; | |||||||||
| 74 | |||||||||||
| 75 | 1 | $self->pid_c($pid); | |||||||||
| 76 | |||||||||||
| 77 | } | ||||||||||
| 78 | else{ | ||||||||||
| 79 | 0 | $a->B; | |||||||||
| 80 | 0 | $b->B; | |||||||||
| 81 | |||||||||||
| 82 | 0 | $self->{input} = $b; | |||||||||
| 83 | 0 | $self->{output} = $a; | |||||||||
| 84 | |||||||||||
| 85 | 0 | eval{ | |||||||||
| 86 | |||||||||||
| 87 | 0 | $self->__backendLoop(); | |||||||||
| 88 | |||||||||||
| 89 | }; | ||||||||||
| 90 | 0 | ▶ | if($@){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | |||||||||||
| 92 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 93 | |||||||||||
| 94 | 0 | print Dumper($@); | |||||||||
| 95 | |||||||||||
| 96 | 0 | exit 1; | |||||||||
| 97 | } | ||||||||||
| 98 | |||||||||||
| 99 | 0 | exit 0; | |||||||||
| 100 | |||||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 0 | ▶ | sub __backendLoop{ | ||||||||
|
Subroutine
__backendLoop: not called CC=2 SCAR=17.9
| |||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | while(my $job = $self->input->receive){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 109 | |||||||||||
| 110 | 0 | $job = Eixo::Queue::Job->unserialize($job); | |||||||||
| 111 | |||||||||||
| 112 | 0 | $self->backend->($job); | |||||||||
| 113 | |||||||||||
| 114 | 0 | $self->output->send($job->serialize); | |||||||||
| 115 | } | ||||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 1000 | ▶ | sub add{ | ||||||||
|
Subroutine
add: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||
| 119 | 1000 | my ($self, $job) = @_; | |||||||||
| 120 | |||||||||||
| 121 | 1000 | ▶ | unless($self->initiated){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 0 | die(ref($self) . '::add Queue not initiated'); | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | 1000 | ▶ | return undef if($self->jobSent); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | |||||||||||
| 127 | 1000 | $self->__toBackend($job); | |||||||||
| 128 | |||||||||||
| 129 | 1000 | $self->jobSent(1); | |||||||||
| 130 | |||||||||||
| 131 | 1000 | return 1; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | 1000 | ▶ | sub __toBackend{ | ||||||||
|
Subroutine
__toBackend: called CC=1 SCAR=0.0
| |||||||||||
| 135 | 1000 | my ($self, $job) = @_; | |||||||||
| 136 | |||||||||||
| 137 | 1000 | $self->output->send($job->serialize); | |||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | 1000 | ▶ | sub wait{ | ||||||||
|
Subroutine
wait: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 141 | 1000 | my ($self) = @_; | |||||||||
| 142 | |||||||||||
| 143 | 1000 | ▶ | if($self->jobSent){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | |||||||||||
| 145 | 1000 | $self->__waitBackend; | |||||||||
| 146 | |||||||||||
| 147 | } | ||||||||||
| 148 | } | ||||||||||
| 149 | 1000 | ▶ | sub __waitBackend{ | ||||||||
|
Subroutine
__waitBackend: called CC=1 SCAR=0.0
| |||||||||||
| 150 | |||||||||||
| 151 | 1000 | my $data = $_[0]->input->receive; | |||||||||
| 152 | |||||||||||
| 153 | 1000 | $_[0]->jobSent(0); | |||||||||
| 154 | |||||||||||
| 155 | 1000 | return Eixo::Queue::Job->unserialize($data); | |||||||||
| 156 | |||||||||||
| 157 | |||||||||||
| 158 | } | ||||||||||
| 159 | |||||||||||
| 160 | |||||||||||
| 161 | 0 | ▶ | sub status{ | ||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 162 | 0 | my ($self) = @_; | |||||||||
| 163 | |||||||||||
| 164 | 0 | $self->jobSent; | |||||||||
| 165 | } | ||||||||||
| 166 | |||||||||||
| 167 | 1 | 1; | |||||||||