line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBGp::Client::AsyncStream; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1351
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
56
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
671
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
0
|
|
|
0
|
0
|
|
my ($class, %args) = @_; |
8
|
|
|
|
|
|
|
my $self = bless { |
9
|
|
|
|
|
|
|
socket => $args{socket}, |
10
|
0
|
|
|
|
|
|
buffer => '', |
11
|
|
|
|
|
|
|
on_line => undef, |
12
|
|
|
|
|
|
|
}, $class; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
0
|
|
sub on_line { $_[0]->{on_line} = $_[1] } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub add_data { |
20
|
0
|
|
|
0
|
0
|
|
my ($self, $bytes) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
$self->{buffer} .= $bytes; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
while (defined(my $line = $self->_try_line)) { |
25
|
0
|
|
|
|
|
|
$self->{on_line}->($line); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub put_line { |
30
|
0
|
|
|
0
|
0
|
|
my ($self, @items) = @_; |
31
|
0
|
|
|
|
|
|
my $cmd = join(" ", @items); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
syswrite $self->{socket}, $cmd . "\x00"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _try_line { |
37
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
38
|
0
|
|
|
|
|
|
my $buffer = \$self->{buffer}; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $len_end = index($$buffer, "\x00"); |
41
|
0
|
0
|
|
|
|
|
return if $len_end == -1; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $len = 0 + substr $$buffer, 0, $len_end; |
44
|
0
|
0
|
|
|
|
|
return if length($$buffer) < $len_end + $len + 2; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
die "Packat is not null-terminated" |
47
|
|
|
|
|
|
|
unless substr($$buffer, $len_end + $len + 1, 1) eq "\x00"; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $line = substr $$buffer, $len_end + 1, $len; |
50
|
0
|
|
|
|
|
|
substr $$buffer, 0, $len_end + $len + 2, ''; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $line; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |