Skip Menu |

This queue is for tickets about the File-Map CPAN distribution.

Report information
The Basics
Id: 56133
Status: rejected
Priority: 0/
Queue: File-Map

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: map_descriptor() func
Date: Wed, 31 Mar 2010 10:34:22 +1100
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
As an idea for a feature, you could make a map_descriptor() available to operate directly on a fileno. It'd be good for inter-operation with POSIX::open() etc and is of course the underlying syscall (even on ms-dos?). I think fcntl(F_GETFL) can fetch the O_RDONLY etc modes to establish a default $mode. Or alternately start with the mode parameter mandatory for map_descriptor() and see about a default later.
I'm not seeing the need for it. There are very few good reasons to work with raw file descriptors in Perl, I don't see why it would be useful. I actually have needed to do this once myself, in POSIX::RT::SharedMem. I resolved it by opening a filehandle like this: open my $fh, '<&', $fd or croak "Can't fdopen($fd): $!";
Subject: Re: [rt.cpan.org #56133] map_descriptor() func
Date: Sat, 03 Apr 2010 11:22:48 +1100
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Leon Timmermans via RT" <bug-File-Map@rt.cpan.org> writes: Show quoted text
> > I'm not seeing the need for it.
Well, it's the fundamental operation, and I think you may already have the code for it, just under a different name. Show quoted text
> I actually have needed to do this once myself, in POSIX::RT::SharedMem. > I resolved it by opening a filehandle like this: > > open my $fh, '<&', $fd or croak "Can't fdopen($fd): $!";
Oh, well, I don't expect it's ideal to make a handle just so fileno() can be applied to get back the fd again, not if it can be easily avoided :-). I suspect under msdos or PERLIO=crlf a plainly opened handle might even have dodgy layers on it, if you decide to error-out on bad layers. Which could mean having to remember :raw open my $fh, '<& :raw', $fd; or open my $fh, '<&', $fd; binmode($fh); or whatever way it is that avoids layers.
On Fri Apr 02 20:23:14 2010, user42@zip.com.au wrote: Show quoted text
> Well, it's the fundamental operation, and I think you may already have > the code for it, just under a different name.
That still doesn't give a use case. Just because you can do something doesn't mean you should, Anyway, implementing it is trivial, so if you really need it somewhere, you could use this: sub map_descriptor { my (undef, $descriptor, $mode, $offset, $length) = @_; _mmap_impl($_[0], $length, $PROTECTION_FOR{$mode}, MAP_SHARED|MAP_FILE, $descriptor, $offset); return; } Show quoted text
> Oh, well, I don't expect it's ideal to make a handle just so fileno() > can be applied to get back the fd again, not if it can be easily avoided
Actually, there are a number of advantages to doing it like that. The most important one is resource management. Filehandles will be close()ed properly, even in the event of an exception. That is not the case for a raw file descriptor.
Subject: Re: [rt.cpan.org #56133] map_descriptor() func
Date: Thu, 08 Apr 2010 10:39:03 +1000
To: bug-File-Map [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Leon Timmermans via RT" <bug-File-Map@rt.cpan.org> writes: Show quoted text
> > Filehandles will be close()ed > properly, even in the event of an exception.
Oh, well, when you're working with an fd it's probably because you don't want that, or it's taken care of elsewhere. An mmap of course doesn't care if the fd is closed before or after the map is unmapped. The key point though is that mmap of an fd is the basic operation and may helpfully be exposed.