Captive-Portal
view release on metacpan or search on metacpan
lib/Captive/Portal/LockHandle.pm view on Meta::CPAN
DEBUG "fd=$fileno, LOCKED";
# reset alarm
ualarm $old_alarm;
}
catch {
# reset alarm
ualarm $old_alarm;
# propagate error
$error = $_;
};
die "$error\n" if $error;
return $lock_handle;
}
else {
my $error;
$mode |= LOCK_NB;
my $retry = $opts{try};
while ( $retry-- > 0 ) {
undef $error;
try {
flock $lock_handle, $mode
or die "fd=$fileno, couldn't lock $file: $!\n";
DEBUG "fd=$fileno, LOCKED";
}
catch { $error = $_; };
if ($error) {
DEBUG $error;
DEBUG "fd=$fileno, lock retries left: $retry";
# sleep for 1ms
usleep 1_000;
next;
}
return $lock_handle;
}
die "$error\n";
}
}
=item $handle->DESTROY()
Called whenever the locked filehandle is destroyed. Just implemented to get proper debug messages for locking/unlocking.
=cut
sub DESTROY {
my $lock_handle = shift;
my $fileno = $lock_handle->fileno;
DEBUG "fd=$fileno, UNLOCKED";
}
1;
=back
=head1 AUTHOR
Karl Gaissmaier, C<< <gaissmai at cpan.org> >>
=head1 LICENSE AND COPYRIGHT
Copyright 2010-2013 Karl Gaissmaier, all rights reserved.
This distribution is free software; you can redistribute it and/or modify it
under the terms of either:
a) the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version, or
b) the Artistic License version 2.0.
=cut
# vim: sw=4
( run in 1.089 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )