line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::DBus::WriteMsg; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
35
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
142
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
112
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
21
|
use Socket (); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
66
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
1581
|
use Protocol::DBus::Socket (); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
110
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
28
|
use parent qw( IO::Framed::Write ); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
37
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %fh_fds; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub DESTROY { |
15
|
2
|
|
|
2
|
|
8978
|
my ($self) = @_; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
13
|
my $fh = delete $fh_fds{ $self->get_write_fh() }; |
18
|
|
|
|
|
|
|
|
19
|
2
|
50
|
|
|
|
61
|
$self->SUPER::DESTROY() if IO::Framed::Write->can('DESTROY'); |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
19
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub enqueue_message { |
25
|
3
|
|
|
3
|
0
|
10
|
my ($self, $buf_sr, $fds_ar) = @_; |
26
|
|
|
|
|
|
|
|
27
|
3
|
50
|
66
|
|
|
6
|
push @{ $fh_fds{$self->get_write_fh()} }, ($fds_ar && @$fds_ar) ? $fds_ar : undef; |
|
3
|
|
|
|
|
64
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->write( |
30
|
|
|
|
|
|
|
$$buf_sr, |
31
|
|
|
|
|
|
|
sub { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# We’re done with the message, so we remove the FDs entry, |
34
|
|
|
|
|
|
|
# which by here should be undef. |
35
|
3
|
|
|
3
|
|
176
|
shift @{ $fh_fds{$self->get_write_fh()} }; |
|
3
|
|
|
|
|
10
|
|
36
|
|
|
|
|
|
|
}, |
37
|
3
|
|
|
|
|
106
|
); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
58
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Receives ($fh, $buf) |
43
|
|
|
|
|
|
|
sub WRITE { |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Only use sendmsg if we actually need to. |
46
|
3
|
50
|
|
3
|
|
91
|
if (my $fds_ar = $fh_fds{ $_[0] }[0]) { |
47
|
0
|
0
|
|
|
|
0
|
die 'Socket::MsgHdr is not loaded!' if !Socket::MsgHdr->can('new'); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
my $msg = Socket::MsgHdr->new( buf => $_[1] ); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$msg->cmsghdr( |
52
|
|
|
|
|
|
|
Socket::SOL_SOCKET(), Socket::SCM_RIGHTS(), |
53
|
|
|
|
|
|
|
pack( 'I!*', @$fds_ar ), |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
my $bytes = Protocol::DBus::Socket::sendmsg_nosignal( $_[0], $msg, 0 ); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# NOTE: This assumes that, on an incomplete write, the ancillary |
59
|
|
|
|
|
|
|
# data (i.e., the FDs) will have been sent, and there is no need |
60
|
|
|
|
|
|
|
# to resend. That appears to be the case on Linux and MacOS, but |
61
|
|
|
|
|
|
|
# I can’t find any actual documentation to that effect. |
62
|
0
|
0
|
|
|
|
0
|
if ($bytes) { |
63
|
0
|
|
|
|
|
0
|
undef $fh_fds{ $_[0] }[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
return $bytes; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
32
|
return Protocol::DBus::Socket::send_nosignal( $_[0], $_[1], 0 ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |