>
> Below is the base code for a forking server.  When I attempt to close my
> child process with an exit(0), it terminates the server application.  Is
> there something I have done wrong or misunderstand?   I stripped
> out all the
> variable initialization, but this code does work for a single iteration
> until I try to close the process started by the first.  Any guidance?
>
>
> __CODE__
> #!perl.exe
> use IPC::Open2;
> use Symbol;
> use Cwd;
>
> $PORT = 50000;      # This should probably be configurable in the end
> $HOST = undef;      # Localhost
>
> # Create listener socket
>
> use IO::Socket;
> $listener = new IO::Socket::INET (
>    LocalAddr => $HOST,
>    LocalPort => $PORT,
>    Proto => 'tcp',
>    Listen => 5,
>    Reuse => 1
>    );
>
> # Exit if problem
>
> die "Socket could not be created: $!\n" unless $listener;
>
> $SIG{CHLD} = 'IGNORE';
> while ($sock = $listener->accept()) {
>    select($sock); $| = 1; select(STDOUT);
> # spin this connection off into a new process (if possible)
>    my $pid = eval("fork");
>    warn "Cannot fork: $!" unless defined($pid);
>    if ($pid) {
>       close $sock;
>       next;
>    }
>    $SIG{CHLD} = 'DEFAULT';
>
>
>    while (<$sock>) {
>       @command = split /\|/, $_;                 # Parse Input on socket
>       chomp(@command);
>       print "Command Array: @command\n" if $debug;  # Verifying Input to
> CLIENT side
>       $opcode     = shift @command;
>       $location   = shift @command;
>       $doctype    = shift @command;
>       $docnumber  = shift @command;
>
>       if (! $open2pid) {            # If $pid not undef then open pipe to
> printing program.
>          my $location = $location || 'NULL';
>          my $program  = $basedir . "/" . $doctype . ".exe";
>          print $program . "\n";
>          if (! -e $program) {
>             $program = $basedir . "/os4baseapi.exe";
>          }
>          if (-e $program) {
>             print $sock "No Subprogram Error, file does not exist, using
> default\n";
>          }
>          my $pgm = "\"$program\" $opcode $location $doctype";
>          $open2pid = open2($RDR,$WTR,$pgm);
>       }
>       if ($opcode ne 'C') {
>          print $WTR $docnumber ."\n";
>          while (<$RDR>) {
>             print $sock $_;
>             chop();
>             $lastoutput = $_;
>             last if /OK/ or /BYE/;   # Exit the reading loop from external
> application on these responses
>          }
>       }
>       if ($opcode eq 'C' or $lastoutput eq 'BYE') {    # Close all
> filehandles
>          print $sock "BYE\n";
>          close $WTR;
>          close $RDR;
>          close($sock);         # Close socket in child process
>          last;                 # Exit current WHILE loop to proceed to
> Exitting child
>       }
>
>       print $sock "OK\n";      # Send command back to client for next
> transmission
>    }
>    exit (0) ; # if undef($pid);
> }
> __END__
>

Ok, I discoverd that the connecting client program was not closing the
socker propely through the normal cleanup at program termination.  Is there
a way to account for this in the server app so it does not crash the server?
Like wrapping the code in an eval of some kind?

Thank you,

Adam Frielink

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to