line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::DBus::WriteMsg; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
31
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
121
|
|
4
|
5
|
|
|
5
|
|
21
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
96
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
21
|
use Socket (); |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
55
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
1529
|
use Protocol::DBus::Socket (); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
95
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
24
|
use parent qw( IO::Framed::Write ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
41
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %fh_fds; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub DESTROY { |
15
|
2
|
|
|
2
|
|
7270
|
my ($self) = @_; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
10
|
my $fh = delete $fh_fds{ $self->get_write_fh() }; |
18
|
|
|
|
|
|
|
|
19
|
2
|
50
|
|
|
|
49
|
$self->SUPER::DESTROY() if IO::Framed::Write->can('DESTROY'); |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
64
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub enqueue_message { |
25
|
3
|
|
|
3
|
0
|
8
|
my ($self, $buf_sr, $fds_ar) = @_; |
26
|
|
|
|
|
|
|
|
27
|
3
|
50
|
66
|
|
|
4
|
push @{ $fh_fds{$self->get_write_fh()} }, ($fds_ar && @$fds_ar) ? $fds_ar : undef; |
|
3
|
|
|
|
|
35
|
|
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
|
|
132
|
shift @{ $fh_fds{$self->get_write_fh()} }; |
|
3
|
|
|
|
|
10
|
|
36
|
|
|
|
|
|
|
}, |
37
|
3
|
|
|
|
|
90
|
); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
47
|
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
|
|
73
|
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
|
|
|
|
|
28
|
return Protocol::DBus::Socket::send_nosignal( $_[0], $_[1], 0 ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |