Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
P is for Practical
 
PerlMonks  

Re: launching another program but using the existing socket

by repson (Chaplain)
on Jul 22, 2001 at 06:26 UTC ( #98752=note: print w/ replies, xml ) Need Help??


in reply to launching another program but using the existing socket

When you exec another process it has access to any open file-handles within your program whose system file desriptor is within the value of $^F.

The system uses file numbers 0=STDIN, 1=STDOUT, 2=STDERR and anything else is higher.

To open using just the fileno, first discover the socket's using fileno($socket) or $socket->fileno and pass that to the execed program on command line or with environment variables.

Then use the open syntax open FOO, ">& $fileno"; or whatever it is in the open documentation, or use $fh = File::Handle->new_from_fd and $fh->fdopen with the fileno.

Alternativly follow nardo's advice because those filehandles are always inherited by an exec'ed process and that will make the client program compatible with inetd.


Comment on Re: launching another program but using the existing socket
Download Code
(tye)Re: launching another program but using the existing socket
by tye (Cardinal) on Jul 23, 2001 at 23:57 UTC

    A couple of fairly minor points:

    First, you probably want open FOO, ">&=$fileno" as using ">&$fileno" will dup() the file descriptor and then open a Perl file handle to it, leaving you with two file descriptors open to the same socket so that closing just the one doesn't shut down the connection.

    Second, I recall recently someone discovering that sockets in Perl are never set to "close on exec" no matter what you do with $^F. I supposed you could consider this a feature, especially in this case. But I'd be a bit shy of depending on it until I found out why it is that way.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-04-20 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls