Salvador Fandiño García > AnyEvent-FileLock-0.02 > AnyEvent::FileLock

Download:
AnyEvent-FileLock-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.02   Source   Latest Release: AnyEvent-FileLock-0.03

NAME ^

AnyEvent::FileLock - Lock files asynchronously

SYNOPSIS ^

  use AnyEvent::FileLock;

  my $w = AnyEvent::FileLock->flock(file => $fn,
                                    cb => sub { ... },
                                    mode => '<',
                                    delay => $seconds,
                                    timeout => $timeout);

DESCRIPTION ^

This module tries to lock some file repeatly until it success or a timeout happens.

API

The function provides a unique method flock accepting the following arguments:

fh => $file_handle

When this argument is given the passed file handle is used as the file locking target.

file => $file_name

When this argument is given a file with the given name will be opened or created and then the module will try to lock it.

type => $lock_type

$lock_type may be fcntl or flock and determines the way used to obtain the lock under the hood.

The default is flock.

In order to use locks of type fcntl, the module Fctnl::Packer has to be also instaled.

cb => $sub_ref

The given function is called once the lock is acquired on the file with the file handle passed as an argument.

In case of error (i.e. timeout) undef will be passed instead of the file handle. The error can be retrieved from $!.

The user is responsible for closing the file handle or calling flock($fh, LOCK_UN) (or the corresponding fcntl(2) F_UNLCK) on it when required.

open_mode => $mode

The mode used to open the file when the argument file is passed. Accepted values are <, >, >>, +< and +>.

lock_mode => $mode

The mode used when locking the file, it accepts the same set of values as open_mode. < means shared access and everything else exclusive access.

mode => $mode

Configures both open_mode and lock_mode.

timeout => $seconds

The operation is aborted if the lock operation can not be completed for the given lapse.

Note that this timeout is aproximate, it is checked just after every failed locking attempt.

delay => $seconds

Time to be delayed between consecutive locking attemps. Defaults to 1 second.

whence => $whence
start => $start
len => $len

When fcntl is selected as the lock type, this three additional arguments can be used to define the section of the file that has to be locked. See fcntl(2) for the details.

SEE ALSO ^

AnyEvent.

"flock" in perlfunc, "fcntl" in perlfunc, fcntl(2), Fcntl, Fcntl::Packer.

AUTHOR ^

Salvador Fandiño, <sfandino@yahoo.com>

COPYRIGHT AND LICENSE ^

Copyright (C) 2013 by Qindel Formaciñn y Servicios S.L.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: