Re: Mailbox locking
Brendan O'Dea <bod@debian.org> writes:
> A better option if you need to use fcntl locking is to write an XS
> module.
I'm amazed that something like this doesn't already exist, but poking
around a little I didn't find it under any obvious name. The code is
basically just several bits like:
int
fcntl_write_lock(fd, whence, start, len)
int fd;
short whence;
long start;
long len;
PROTOTYPE: $$$$
CODE:
{
struct flock flock;
flock.l_type = F_WRLCK;
flock.l_whence = whence;
flock.l_start = start;
flock.l_len = len;
RETVAL = (fcntl(fd, F_SETLK, &flock) == 0);
}
OUTPUT:
RETVAL
as an example of one operation; a better interface could be devised that
would handle Perl file objects instead of file descriptors, and it would
be good to have a short-hand way of locking the entire file, but you get
the general idea. I expect that writing the whole module would only take
an XS programmer four or five hours, including docs and packaging.
--
Russ Allbery (rra@debian.org) <http://www.eyrie.org/~eagle/>
Reply to: