renodino has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to come up with a generic way to pass filehandles between threads (wo/ having a priori knowledge of the filehandle's modes/layers). The only way I know of is to pass the fileno, and re-open in the receiving thread using open(FH, "&$fileno").
2 questions:
1) How can I get the open()'d modes for a filehandle on Win32 ? fcntl() doesn't work there, and I can't seem to find a Win32 module to do it...
2) I need to be able to re-apply the access modes and PerlIO layers in the recving thread. I can get the layers via PerlIO::get_layers(), and (hopefully) I can get the modes via a Win32 call (or via fcntl() everywhere else).
However, when I try to apply layers to a fileno open(), Perl barks in 2 arg open(), and creates a new file in 3 arg open().
Is there any way around this problem ?use PerlIO; my $fd; open($fd, '+>>:raw', 'somefile.data') || die $!; my $layers = ':' . join(':', PerlIO::get_layers($fd)); print "$layers\n"; # # this creates a new file named "&3" # my $fn = fileno($fd); my $fd2; open($fd2, '+>>' . $layers, '&' . $fn) || die $!; # # this dies with "Invalid argument at filemode.pl line ..." # my $fd3; open($fd3, '+>>' . $layers . ' &' . $fn) || die $!; close $fd; close $fd2; close $fd3;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't open($newfh, $mode_layers, '&' . fileno($fh))
by Errto (Vicar) on Feb 10, 2006 at 21:26 UTC | |
by renodino (Curate) on Feb 10, 2006 at 21:51 UTC | |
|
Re: Can't open($newfh, $mode_layers, '&' . fileno($fh))
by BrowserUk (Patriarch) on Feb 11, 2006 at 17:01 UTC | |
by renodino (Curate) on Feb 11, 2006 at 18:23 UTC |