line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Mux::Buffer ; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
32550
|
use strict ; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
145
|
|
4
|
4
|
|
|
4
|
|
532
|
use IO::Mux::Packet ; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
71
|
|
5
|
4
|
|
|
4
|
|
19
|
use Carp ; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1346
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.08' ; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
19
|
|
|
19
|
0
|
35
|
my $class = shift ; |
13
|
|
|
|
|
|
|
|
14
|
19
|
|
|
|
|
33
|
my $this = {} ; |
15
|
19
|
|
|
|
|
36
|
$this->{buf} = '' ; |
16
|
19
|
|
|
|
|
28
|
$this->{closed} = 0 ; |
17
|
|
|
|
|
|
|
|
18
|
19
|
|
|
|
|
99
|
return bless($this, $class) ; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub get_length { |
23
|
81
|
|
|
81
|
0
|
377
|
my $this = shift ; |
24
|
|
|
|
|
|
|
|
25
|
81
|
|
|
|
|
574
|
return length($this->{buf}) ; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get_data { |
30
|
28
|
|
|
28
|
0
|
924
|
my $this = shift ; |
31
|
|
|
|
|
|
|
|
32
|
28
|
|
|
|
|
201
|
return $this->{buf} ; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub is_closed { |
37
|
35
|
|
|
35
|
0
|
44
|
my $this = shift ; |
38
|
|
|
|
|
|
|
|
39
|
35
|
|
|
|
|
139
|
return $this->{closed} ; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub push_packet { |
44
|
34
|
|
|
34
|
0
|
450
|
my $this = shift ; |
45
|
34
|
|
|
|
|
33
|
my $packet = shift ; |
46
|
|
|
|
|
|
|
|
47
|
34
|
100
|
|
|
|
101
|
if ($packet->is_eof()){ |
48
|
6
|
|
|
|
|
25
|
$this->{closed} = 1 ; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
28
|
|
|
|
|
76
|
$this->{buf} .= $packet->get_data() ; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub shift_data { |
57
|
28
|
|
|
28
|
0
|
41
|
my $this = shift ; |
58
|
28
|
|
100
|
|
|
69
|
my $len = shift || 0 ; |
59
|
|
|
|
|
|
|
|
60
|
28
|
100
|
|
|
|
57
|
return '' if $len < 0 ; |
61
|
|
|
|
|
|
|
|
62
|
27
|
100
|
|
|
|
62
|
if ($this->get_length() < $len){ |
63
|
1
|
|
|
|
|
5
|
croak("Buffer contains less than '$len' bytes (length is " . |
64
|
|
|
|
|
|
|
$this->get_length() ." bytes)") ; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
26
|
|
|
|
|
69
|
my $data = substr($this->{buf}, 0, $len) ; |
68
|
26
|
|
|
|
|
52
|
substr($this->{buf}, 0, $len) = '' ; |
69
|
|
|
|
|
|
|
|
70
|
26
|
|
|
|
|
84
|
return $data ; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1 ; |