I couldn't find it actually documented that Net::Server redirects STDIN and STDOUT as you appear to expect it to. It is implied by the documentation but I saw no actual mention of this fact, though it was rather a quick scan of the documentation. I was expecting to find something quite explicit on that point.

Rummaging through the code I find:

*STDIN = \*{ $prop->{client} }; *STDOUT = \*{ $prop->{client} } if ! $prop->{client}->isa('IO::Soc +ket::SSL'); # ... select(STDOUT);

Which is a pretty lousy way to do something like this. Copying file handles via symbol table glob manipulations is a pretty fundamentally broken technique in my experience. I've found it to be buggy. More importantly, it violates important properties of file handles and file descriptors.

If you want to "duplicate some handles" (as a comment in the code notes), then you should dup() them, which is done as documented in open: open STDIN, "<&" . fileno($prop->{client}) ..., for example; or use "<&=" if you just want to fdopen() rather than dup().

Of course, that would interfere with "magical" file handles (such a tied ones), so the code should probably look more like:

my $fileno= fileno $prop->{client}; if( defined $fileno ) { open STDIN, "<&$fileno" or die ...; open STDOUT, ">&$fileno" or die ...; } else { close STDIN; close STDOUT; *STDIN= \*{ $prop->{client} }; *STDOUT= \*{ $prop->{client} }; }

Note that I close STDIN and STDOUT before I overwrite them, as my experience is that the relation between glob life cycle and file handle life cycle is buggy.

Unfortunately, none of this looks to me like a "smoking gun" to explain your particular problem. But you could try patching Net/Server.pm and see if it makes a difference.

If I were having this problem, then I'd debug the server and watch what sockets gets created when a connection is opened and what STDOUT gets set to before my method gets called.

I suspect that you could even stop using IO::Pipe and you'd still have this problem.

- tye        


In reply to Re: (Seemingly) Broken interactions between Net::Server and IO::Pipe? (dup) by tye
in thread (Seemingly) Broken interactions between Net::Server and IO::Pipe? by bmcatt

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.