Apache2-SSI
view release on metacpan or search on metacpan
lib/Apache2/SSI/SharedMem.pm view on Meta::CPAN
$self->{id} = undef();
$self->{locked} = 0;
$self->{owner} = $$;
$self->{removed} = 0;
$self->{semid} = undef();
return( $self );
}
sub addr { return( shift->_set_get_scalar( 'addr', @_ ) ); }
sub attach
{
my $self = shift( @_ );
my $flags = shift( @_ );
$flags = $self->flags if( !defined( $flags ) );
my $addr = $self->addr;
return( $addr ) if( defined( $addr ) );
my $id = $self->id;
return( $self->error( "No shared memory id! Have you opened it first?" ) ) if( !length( $id ) );
$addr = shmat( $id, undef(), $flags );
return( $self->error( "Unable to attach to shared memory: $!" ) ) if( !defined( $addr ) );
$self->addr( $addr );
return( $addr );
}
sub create { return( shift->_set_get_boolean( 'create', @_ ) ); }
sub destroy { return( shift->_set_get_boolean( 'destroy', @_ ) ); }
sub detach
{
lib/Apache2/SSI/SharedMem.pod view on Meta::CPAN
my $shmem = Apache2::SSI::SharedMem->new(
create => 1,
destroy => 0,
key => 'my_memory',
# 64K
size => 65536,
) || die( Apache2::SSI::SharedMem->error );
=head2 addr
Returns the address of the shared memory segment once it has been attached to this address space.
=head2 attach
Attach the shared memory segment to this address space and returns its address.
Upon error, it returns C<undef> and sets an error that can be retrieved with the error method:
my $addr = $shem->attach || die( $shem->error );
A shared memory segment object must be first created with the L</open> method, because L</attach> calls L<IPC::SysV/shmat> with the shared memory id and this id is returned upon using the L</open> method.
=head2 create
Set or get the boolean value to true to indicate you want to create the shared memory block if it does not exist already. Default to false.
=head2 destroy
Set or get the boolean value to indicate that the shared memory should be automatically destroyed when the module object is destroyed. See L<perlmod> for more information about module object destruction.
=head2 detach
Quoting the IPC documentation, this detaches the shared memory segment located at the address specified by L</attach> from this address space.
It returns C<undef> if it is not attached anymore, but without setting an error.
=head2 exclusive
Set or get the boolean value to affect the open flags in exclusive mode.
=head2 exists
Checks if the shared memory identified with C<key> exists.
It takes the same arguments as L</open> and returns 1 if the shared memory exists or 0 otherwise.
( run in 0.645 second using v1.01-cache-2.11-cpan-e1769b4cff6 )