in reply to Re^2: Using latest code
in thread Using latest code
Ever heard of inetd? Or NPH CGI? It is quite easy to pass an open socket to a child process.
The way to do that with system (avoids fork amd exec and so is more portable) is simply to dup the socket to be STDIN and/or STDOUT (file descriptors 0 and/or 1, since file handles don't get inherited).
Use the sample code in open if you want to save then restore your existing STDIN/STDOUT, then just do:
# (save STDIN/STDOUT here) open STDIN, "<&".fileno(*SOCK) or die "Can't dup SOCK to STDIN: $!$/"; open STDOUT, ">&".fileno(*SOCK) or die "Can't dup SOCK to STDOUT: $!$/"; system( ... ) and ...; # (restore STDIN/STDOUT here)
Perl is smart enough to ensure that STDIN remains fd 0 and STDOUT remains fd 1 for the above.
- tye
|
|---|