line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Memcached::Conn; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
21
|
use common::sense; |
|
5
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
21
|
|
4
|
5
|
|
|
5
|
|
189
|
use base 'AnyEvent::Connection::Raw'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
293
|
|
5
|
5
|
|
|
5
|
|
17
|
use AnyEvent::Memcached; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
105
|
|
6
|
5
|
|
|
5
|
|
21
|
use AnyEvent::Connection::Util; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $NL = "\015\012"; |
9
|
|
|
|
|
|
|
our $QRNL = qr<\015?\012>; |
10
|
|
|
|
|
|
|
our $VERSION = $AnyEvent::Memcached::VERSION; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub reader { |
13
|
0
|
|
|
0
|
0
|
|
my ($self,%args) = @_; |
14
|
0
|
0
|
|
|
|
|
$args{cb} or return $self->event( error => "no cb for command at @{[ (caller)[1,2] ]}" ); |
|
0
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
$self->{h} or return $args{cb}->(undef,"Not connected"); |
16
|
0
|
|
0
|
|
|
|
my $result = $args{res} || {}; |
17
|
0
|
0
|
|
|
|
|
my $cut = exists $args{namespace} ? length $args{namespace} : 0; |
18
|
0
|
|
|
|
|
|
my $reader;$reader = sub { |
19
|
0
|
|
|
0
|
|
|
shift; |
20
|
0
|
0
|
|
|
|
|
defined( local $_ = shift ) or return $args{cb}(undef,@_); |
21
|
0
|
0
|
|
|
|
|
warn "<<$args{id} $_" if $self->{debug}; |
22
|
0
|
0
|
|
|
|
|
if ($_ eq "END") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
undef $reader; |
24
|
0
|
|
|
|
|
|
$args{cb}( $result ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif (!length) { |
27
|
0
|
|
|
|
|
|
warn "Skip empty line"; |
28
|
0
|
|
|
|
|
|
$self->{h}->unshift_read( line => $reader); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif( /^VALUE (\S+) (\d+) (\d+)(?:| (.+))$/ ) { |
31
|
0
|
|
|
|
|
|
my ($key,$flags,$len,$cas) = ($1,$2,$3,$4); |
32
|
|
|
|
|
|
|
#warn "have to read $1 $2 $3 $4"; |
33
|
|
|
|
|
|
|
$self->recv( $3+2 => cb => sub { |
34
|
|
|
|
|
|
|
#shift; |
35
|
0
|
|
|
|
|
|
my $data = shift; |
36
|
0
|
|
|
|
|
|
substr($data,$len) = ''; # trim out data outside length |
37
|
|
|
|
|
|
|
#$data = substr($data,0,length($data)-2); |
38
|
0
|
0
|
|
|
|
|
$key = substr($key, $cut) if substr($key, 0, $cut) eq $args{namespace}; |
39
|
0
|
0
|
|
|
|
|
warn "+ received data $key: $data" if $self->{debug}; |
40
|
0
|
0
|
|
|
|
|
$result->{$key} = { |
41
|
|
|
|
|
|
|
data => $data, |
42
|
|
|
|
|
|
|
flags => $flags, |
43
|
|
|
|
|
|
|
$cas ? (cas => $cas) : (), |
44
|
|
|
|
|
|
|
};#{ data => $data, $cas ? (cas => $cas) : () }; |
45
|
0
|
|
|
|
|
|
$self->{h}->unshift_read( line => $reader); |
46
|
0
|
|
|
|
|
|
}); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
|
die "Wrong data received: ".dumper($_)."($!)"; |
50
|
|
|
|
|
|
|
#$args{cb}(undef,$_); |
51
|
|
|
|
|
|
|
#$self->handle_errors($_); |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
}; |
54
|
0
|
|
|
|
|
|
$self->{h}->push_read( line => $reader ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |