| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# This file is part of Riak-Light |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This software is copyright (c) 2013 by Weborama. |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
## no critic (RequireUseStrict, RequireUseWarnings) |
|
10
|
|
|
|
|
|
|
package Riak::Light::Timeout::SelectOnRead; |
|
11
|
|
|
|
|
|
|
{ |
|
12
|
|
|
|
|
|
|
$Riak::Light::Timeout::SelectOnRead::VERSION = '0.10'; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
## use critic |
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
2081
|
use POSIX qw(ETIMEDOUT ECONNRESET); |
|
|
2
|
|
|
|
|
12
|
|
|
|
2
|
|
|
|
|
118
|
|
|
17
|
2
|
|
|
2
|
|
357
|
use IO::Select; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
212
|
|
|
18
|
2
|
|
|
2
|
|
13
|
use Time::HiRes; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
42
|
|
|
19
|
2
|
|
|
2
|
|
754
|
use Config; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
136
|
|
|
20
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
184
|
|
|
21
|
2
|
|
|
2
|
|
11
|
use Moo; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
39
|
|
|
22
|
2
|
|
|
2
|
|
1181
|
use Types::Standard -types; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
59
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
with 'Riak::Light::Timeout'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# ABSTRACT: proxy to read/write using IO::Select as a timeout provider only for READ operations |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has socket => ( is => 'ro', required => 1 ); |
|
29
|
|
|
|
|
|
|
has in_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); |
|
30
|
|
|
|
|
|
|
has out_timeout => ( is => 'ro', isa => Num, default => sub {0.5} ); |
|
31
|
|
|
|
|
|
|
has select => ( is => 'ro', default => sub { IO::Select->new } ); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub BUILD { |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#carp "Should block in Write Operations, be careful"; |
|
36
|
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
0
|
122
|
$_[0]->select->add( $_[0]->socket ); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub DEMOLISH { |
|
41
|
2
|
|
|
2
|
0
|
13550
|
$_[0]->clean(); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub clean { |
|
45
|
3
|
|
|
3
|
0
|
60
|
$_[0]->select->remove( $_[0]->socket ); |
|
46
|
3
|
|
|
|
|
215
|
$_[0]->socket->close; |
|
47
|
3
|
|
|
|
|
335
|
$! = ETIMEDOUT; ## no critic (RequireLocalizedPunctuationVars) |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub is_valid { |
|
51
|
6
|
|
|
6
|
0
|
40
|
scalar $_[0]->select->handles; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub sysread { |
|
55
|
3
|
|
|
3
|
0
|
15
|
my $self = shift; |
|
56
|
3
|
50
|
|
|
|
16
|
$self->is_valid |
|
57
|
|
|
|
|
|
|
or $! = ECONNRESET, |
|
58
|
|
|
|
|
|
|
return; ## no critic (RequireLocalizedPunctuationVars) |
|
59
|
|
|
|
|
|
|
|
|
60
|
3
|
100
|
|
|
|
104
|
return $self->socket->sysread(@_) |
|
61
|
|
|
|
|
|
|
if $self->select->can_read( $self->in_timeout ); |
|
62
|
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
500714
|
$self->clean(); |
|
64
|
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
7
|
undef; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub syswrite { |
|
69
|
3
|
|
|
3
|
0
|
7
|
my $self = shift; |
|
70
|
3
|
100
|
|
|
|
16
|
$self->is_valid |
|
71
|
|
|
|
|
|
|
or $! = ECONNRESET, |
|
72
|
|
|
|
|
|
|
return; ## no critic (RequireLocalizedPunctuationVars) |
|
73
|
2
|
|
|
|
|
85
|
$self->socket->syswrite(@_); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |