| 1 | package POSIX::RT::SharedMem; | ||||||||||||||||||||||||||||
| 2 | 2 | $POSIX::RT::SharedMem::VERSION = '0.10'; | |||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Exporter 5.57 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Fcntl qw/O_RDONLY O_WRONLY O_RDWR O_CREAT/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use File::Map 'map_handle'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | our @EXPORT_OK = qw/shared_open shared_unlink/; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | XSLoader::load(__PACKAGE__, __PACKAGE__->VERSION); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my $default_perms = oct '600'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | 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 | 4 | ▶ | my (undef, $name, $mode, %other) = @_; | ||||||||||||||||||||||||||
|
Subroutine
shared_open: called CC=13 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | my %options = ( | |||||||||||||||||||||||||||
| 30 | perms => $default_perms, | ||||||||||||||||||||||||||||
| 31 | offset => 0, | ||||||||||||||||||||||||||||
| 32 | flags => 0, | ||||||||||||||||||||||||||||
| 33 | %other, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | 4 | ▶ | croak 'Not enough arguments for shared_open' if @_ < 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 4 | ▶ | $mode = '<' if not defined $mode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | croak 'No such mode' if not defined $flag_for{$mode}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 4 | ▶ | croak 'Size must be given in creating mode' if $flag_for{$mode} & O_CREAT and $options{size} == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flag_for{$mode} & 64 and $options{"size"} == 0
MC/DC0%0/2
$flag_for{$mode} & 64 and $options{"size"} == 0
$flag_for{$mode} & 64
$options{"size"} == 0
Truth table66%2/3
A and B
A= $flag_for{$mode} & 64B= $options{"size"} == 0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | my $fh = _shm_open($name, $flag_for{$mode} | $options{flags}, $options{perms}); | |||||||||||||||||||||||||||
| 41 | 2 | ▶ | $options{after_open}->($fh, \%options) if defined $options{after_open}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | $options{size} = -s $fh if not defined $options{size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | croak 'Can\'t map empty file' if $options{size} == 0; # Should never happen | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | truncate $fh, $options{size} if $options{size} > -s $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | $options{before_mapping}->($fh, \%options) if defined $options{before_mapping}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 2 | map_handle $_[0], $fh, $mode, $options{offset}, $options{size}; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | return $fh if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | close $fh or croak "Could not close shared filehandle: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 1 | return; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | 1; # End of POSIX::RT::SharedMem | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | #ABSTRACT: Create/open or unlink POSIX shared memory objects in Perl | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||