(on WinXP, AS 5.8.6)

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().

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;
Is there any way around this problem ?

In reply to Can't open($newfh, $mode_layers, '&' . fileno($fh)) by renodino

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.