| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
|
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2014 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Gearman; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1382
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
101
|
|
|
9
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
121
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
15
|
use base qw( IO::Socket::IP ); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
8145
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
C - provide a synchronous concrete Gearman implementation |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This module provides a simple synchronous concrete implementation to run a |
|
22
|
|
|
|
|
|
|
L or L on top of. It |
|
23
|
|
|
|
|
|
|
shouldn't be used directly; see instead |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=over 2 |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=item * |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
L |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item * |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
L |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=back |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 $gearman = Net::Gearman->new( %args ) |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns a new C object. Takes the same arguments as |
|
44
|
|
|
|
|
|
|
C. Sets a default value for C if not provided of |
|
45
|
|
|
|
|
|
|
4730. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
2
|
|
|
2
|
1
|
1926
|
my $class = shift; |
|
52
|
2
|
50
|
|
|
|
17
|
my %args = @_ == 1 ? ( PeerHost => shift ) : @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
2
|
|
50
|
|
|
7
|
$args{PeerService} //= 4730; |
|
55
|
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
19
|
return $class->SUPER::new( %args ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub gearman_state |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
9
|
|
|
9
|
0
|
16
|
my $self = shift; |
|
62
|
9
|
|
100
|
|
|
11
|
${*$self}{gearman} ||= {}; |
|
|
9
|
|
|
|
|
69
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new_future |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
|
68
|
3
|
|
|
|
|
19
|
return Net::Gearman::Future->new( $self ); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub do_read |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
|
50
|
|
|
15
|
my $buffer = $self->gearman_state->{gearman_buffer} // ""; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# TODO: consider an on_recv_packet to make this more efficient |
|
78
|
2
|
|
|
|
|
22
|
$self->sysread( $buffer, 8192, length $buffer ); |
|
79
|
2
|
|
|
|
|
63
|
$self->on_recv( $buffer ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
7
|
$self->gearman_state->{gearman_buffer} = $buffer; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
package # hide |
|
85
|
|
|
|
|
|
|
Net::Gearman::Future; |
|
86
|
3
|
|
|
3
|
|
43833
|
use base qw( Future ); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
3398
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub new |
|
89
|
|
|
|
|
|
|
{ |
|
90
|
3
|
|
|
3
|
|
8
|
my $class = shift; |
|
91
|
3
|
|
|
|
|
7
|
my ( $gearman ) = @_; |
|
92
|
3
|
|
|
|
|
22
|
my $self = $class->SUPER::new; |
|
93
|
3
|
|
|
|
|
38
|
$self->{gearman} = $gearman; |
|
94
|
3
|
|
|
|
|
18
|
return $self; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub await |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
2
|
|
|
2
|
|
981
|
my $self = shift; |
|
100
|
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
16
|
while( !$self->is_ready ) { |
|
102
|
2
|
|
|
|
|
27
|
$self->{gearman}->do_read; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Paul Evans |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
0x55AA; |