*STDIN = $c; # $c is child socket

Well, no wonder you have problems. Using symbol table globs to copy around file handles is usually a pretty bad idea, in my experience.

I can't figure out how to ensure that I always open fileno 1

open covers this. You close fileno 1 and then immediately reopen STDOUT and Perl even goes to a little extra effort to make sure fileno 1 is what you get (and this is documented). But ">&=" doesn't "open" any file descriptors, it causes a file handle to be associated with an already-open file descriptor. You want ">&" instead (which dup()s a file descriptor).

There is even an example of how to redirect STDOUT and STDERR (and then restore them) in the open documentation. To do STDIN andn STDOUT and not worry about restoring them, you should use something like:

open( STDIN, "<&".fileno($c) ) # also closes old STDIN or die "Can't redirect STDIN from socket: $!\n"; open( STDOUT, ">&".fi­leno($c) ) # also closes old STDOUT or die "Can't redirect STDOUT to socket: $!\n";

- tye        


In reply to Re: STDOUT changing descritpors (open, no =) by tye
in thread STDOUT changing descritpors by suaveant

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.