line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POSIX::RT::SharedMem; |
2
|
|
|
|
|
|
|
$POSIX::RT::SharedMem::VERSION = '0.10'; |
3
|
1
|
|
|
1
|
|
10409
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Exporter 5.57 'import'; |
|
1
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
5
|
use XSLoader; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
9
|
1
|
|
|
1
|
|
5
|
use Fcntl qw/O_RDONLY O_WRONLY O_RDWR O_CREAT/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1005
|
use File::Map 'map_handle'; |
|
1
|
|
|
|
|
14211
|
|
|
1
|
|
|
|
|
7
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw/shared_open shared_unlink/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
XSLoader::load(__PACKAGE__, __PACKAGE__->VERSION); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $default_perms = oct '600'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my %flag_for = ( |
20
|
|
|
|
|
|
|
'<' => O_RDONLY, |
21
|
|
|
|
|
|
|
'+<' => O_RDWR, |
22
|
|
|
|
|
|
|
'>' => O_WRONLY | O_CREAT, |
23
|
|
|
|
|
|
|
'+>' => O_RDWR | O_CREAT, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub shared_open { ## no critic (Subroutines::RequireArgUnpacking) |
27
|
0
|
|
|
0
|
|
|
my (undef, $name, $mode, %other) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my %options = ( |
30
|
|
|
|
|
|
|
perms => $default_perms, |
31
|
|
|
|
|
|
|
offset => 0, |
32
|
|
|
|
|
|
|
flags => 0, |
33
|
|
|
|
|
|
|
%other, |
34
|
|
|
|
|
|
|
); |
35
|
0
|
0
|
|
|
|
|
croak 'Not enough arguments for shared_open' if @_ < 2; |
36
|
0
|
0
|
|
|
|
|
$mode = '<' if not defined $mode; |
37
|
0
|
0
|
|
|
|
|
croak 'No such mode' if not defined $flag_for{$mode}; |
38
|
0
|
0
|
0
|
|
|
|
croak 'Size must be given in creating mode' if $flag_for{$mode} & O_CREAT and $options{size} == 0; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $fh = _shm_open($name, $flag_for{$mode} | $options{flags}, $options{perms}); |
41
|
0
|
0
|
|
|
|
|
$options{after_open}->($fh, \%options) if defined $options{after_open}; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
$options{size} = -s $fh if not defined $options{size}; |
44
|
0
|
0
|
|
|
|
|
croak 'Can\'t map empty file' if $options{size} == 0; # Should never happen |
45
|
0
|
0
|
|
|
|
|
truncate $fh, $options{size} if $options{size} > -s $fh; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
$options{before_mapping}->($fh, \%options) if defined $options{before_mapping}; |
48
|
0
|
|
|
|
|
|
map_handle $_[0], $fh, $mode, $options{offset}, $options{size}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
return $fh if defined wantarray; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
close $fh or croak "Could not close shared filehandle: $!"; |
53
|
0
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; # End of POSIX::RT::SharedMem |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#ABSTRACT: Create/open or unlink POSIX shared memory objects in Perl |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |