line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Framed::Write; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
323
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
302
|
use IO::SigGuard (); |
|
1
|
|
|
|
|
2144
|
|
|
1
|
|
|
|
|
17
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
215
|
use IO::Framed::X (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
487
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
2
|
|
|
2
|
0
|
1617
|
my ( $class, $out_fh ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
|
|
7
|
my $self = { |
14
|
|
|
|
|
|
|
_out_fh => $out_fh, |
15
|
|
|
|
|
|
|
_writer => \&_write_now, |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
9
|
return bless $self, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
0
|
0
|
0
|
sub get_write_fh { return $_[0]->{'_out_fh'} } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub disable_write_queue { |
24
|
0
|
0
|
0
|
0
|
0
|
0
|
if ( $_[0]->{'_write_queue'} && @{ $_[0]->{'_write_queue'} } ) { |
|
0
|
|
|
|
|
0
|
|
25
|
0
|
|
|
|
|
0
|
die 'Refuse to disable non-empty write queue!'; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
$_[0]->{'_writer'} = \&_write_now; |
29
|
0
|
|
|
|
|
0
|
return $_[0]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub enable_write_queue { |
33
|
1
|
|
50
|
1
|
0
|
8
|
$_[0]->{'_write_queue'} ||= []; |
34
|
1
|
|
|
|
|
2
|
$_[0]->{'_writer'} = \&_enqueue_write; |
35
|
1
|
|
|
|
|
4
|
return $_[0]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub write { |
39
|
65539
|
|
|
65539
|
0
|
97368
|
$_[0]->{'_writer'}->(@_); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#====================================================================== |
43
|
|
|
|
|
|
|
#blocking |
44
|
|
|
|
|
|
|
#====================================================================== |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _write_now { |
47
|
65537
|
|
|
65537
|
|
142968
|
local $!; |
48
|
|
|
|
|
|
|
|
49
|
65537
|
100
|
|
|
|
110450
|
IO::SigGuard::syswrite( $_[0]->{'_out_fh'}, $_[1] ) or do { |
50
|
1
|
|
|
|
|
59
|
die IO::Framed::X->create('WriteError', $!); |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
65536
|
50
|
|
|
|
452827
|
$_[2]->() if $_[2]; |
54
|
|
|
|
|
|
|
|
55
|
65536
|
|
|
|
|
137842
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#====================================================================== |
59
|
|
|
|
|
|
|
#non-blocking |
60
|
|
|
|
|
|
|
#====================================================================== |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _enqueue_write { |
63
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
2
|
push @{ $self->{'_write_queue'} }, \@_; |
|
2
|
|
|
|
|
4
|
|
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
5
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub flush_write_queue { |
73
|
4097
|
|
|
4097
|
0
|
155621
|
my ($self) = @_; |
74
|
|
|
|
|
|
|
|
75
|
4097
|
|
|
|
|
8994
|
while ( my $qi = $self->{'_write_queue'}[0] ) { |
76
|
4097
|
100
|
|
|
|
6607
|
return 0 if !$self->_write_now_then_callback( @$qi ); |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
4
|
shift @{ $self->{'_write_queue'} }; |
|
2
|
|
|
|
|
10
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
7
|
return 1; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub get_write_queue_count { |
85
|
3
|
|
|
3
|
0
|
694
|
my ($self) = @_; |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
|
|
6
|
return 0 + @{ $self->{'_write_queue'} }; |
|
3
|
|
|
|
|
11
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub forget_write_queue { |
91
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
my $count = @{ $self->{'_write_queue'} }; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
@{ $self->{'_write_queue'} } = (); |
|
0
|
|
|
|
|
0
|
|
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
0
|
return $count; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _write_now_then_callback { |
103
|
4097
|
|
|
4097
|
|
8379
|
local $!; |
104
|
|
|
|
|
|
|
|
105
|
4097
|
|
66
|
|
|
8390
|
my $wrote = IO::SigGuard::syswrite( $_[0]->{'_out_fh'}, $_[1] ) || do { |
106
|
|
|
|
|
|
|
if ($! && !$!{'EAGAIN'} && !$!{'EWOULDBLOCK'}) { |
107
|
|
|
|
|
|
|
die IO::Framed::X->create('WriteError', $!); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return undef; |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
|
113
|
2
|
50
|
|
|
|
888
|
if ($wrote == length $_[1]) { |
114
|
2
|
|
|
|
|
4
|
$_[0]->{'_write_queue_partial'} = 0; |
115
|
2
|
50
|
|
|
|
9
|
$_[2]->() if $_[2]; |
116
|
2
|
|
|
|
|
10
|
return 1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
#Trim the bytes that we did send. |
120
|
0
|
|
|
|
|
|
substr( $_[1], 0, $wrote ) = q<>; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
#This seems useful to track … ?? |
123
|
0
|
|
|
|
|
|
$_[0]->{'_write_queue_partial'} = 1; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return 0; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |