Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: (Seemingly) Broken interactions between Net::Server and IO::Pipe? (dup)

by tye (Sage)
on Mar 08, 2006 at 16:41 UTC ( [id://535209]=note: print w/replies, xml ) Need Help??

in reply to (Seemingly) Broken interactions between Net::Server and IO::Pipe?

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/ 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        

Replies are listed 'Best First'.
Re^2: (Seemingly) Broken interactions between Net::Server and IO::Pipe? (dup)
by bmcatt (Friar) on Mar 08, 2006 at 18:53 UTC
    Ooooh... That actually seems to fix it! Yippeee!!! Thanks so much, tye. Now to go find the author of Net::Server and convince him that he needs to patch it.
      This patch and many others are now in 0.91 on CPAN.

      Thanks tye.

      my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://535209]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-07-14 01:38 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.