in reply to Re: Re: inetd spawned perl problem
in thread inetd spawned perl problem

Here is my interpretation of what you describe:

A client process "C" connects to port 9876.
Inetd accepts the connection, forks, then execs() your perl program "P".
Your perl program starts a remsh process "S" which connects to a remote host and process "R".

The process P is running this code:

open(RCMD, "remsh $h -l $u $script |") || die $!; while (<RCMD>) { print $_; }

I think what you are asking is how your Perl program P can detect if the client C exits (or otherwises closes the socket connection). Right now it may wait a long time on <RCMD> and not give an error until the "print $_".

If this is a correct understanding, then what I suggested above should work. The STDIN and STDOUT of your Perl process P are both connected to the socket connection that "C" connected to and inetd accepted. A call to select() or can_read() should detect when that socket connection is closed.

Replies are listed 'Best First'.
Re: Re: Re: Re: inetd spawned perl problem
by vasu (Novice) on May 12, 2003 at 18:48 UTC
    Thank you very much for your pointers. The problem was solved by following your suggestions. The new code looks like:
    while (! eof(RCMD)) { my @fds = $sel->can_read(5); #print NSY "FDS = @fds\n"; if ($#fds == 0) { my $in = <RCMD>; print $in; } else { my @fds = $wsel->can_read(0); #print NSY "FDS = @fds\n"; if ($#fds != 0) { #print NSY "Closing as stdout closed\n"; exit(0); } } }