Pb $SIG{CHLD}=sub{wait()}; in Perl 5.8.0

  • Thread starter Sébastien Cottalorda
  • Start date
S

Sébastien Cottalorda

Hi all,

Since I migrate a Perl Socket application from perl 5.6.0 to 5.8.0, I
encoutered problem with the $SIG{CHLD} interrupt.

Here is sample of my code (server side):

use IO::Socket;
my $port_recep=12345;
my ($server, $client);
my ($port,$iaddr);
my $server= IO::Socket::INET->new(LocalPort=> $port_recep,
Type=> SOCK_STREAM,
Reuse=>1,
Listen=>10)
or die "Couln\'t be a tcp server on $port_recep $@\n";

$SIG{CHLD} = sub { wait () };
while ($client=$server->accept()) {
$pid = fork ();
unless (defined($pid)) {
print "Impossible to fork : $!";
exit 1;
}
if ($pid == 0){
$port = $client->peerport();
$iaddr= $client->peerhost();
print "Connexion accepted from $iaddr on port $port\n";
# do the treatment ....
print "Son has finished\n";
close($client);
exit;
}
}
print "Father has finished. It\'s not normal\n";
close($server);
exit 0;


When a connexion cames, it was taken by the son, and the father dies just
after the son has finished his job.

If someone has a clue.

Thanks in advance.

Sébastien
 
S

Sébastien Cottalorda

Stefan said:
/--- snip code ---/



It might be related to the fact the different versions of Perl handle
calls differently. Don't ask me about the underlaying details - try a
Google/Groups search on "Perl EINTR" and/or "Perl EINTR accept".

In your code, you don't really check the status of the accept() call. If
you do, you'll probably see that accept() return status-code 4 (EINTR). In
my experience, that never happens the 1st time a connection is accepted.
That may explain that the father dies after the son has completed.

Try adding some accept() status handling - this is a piece of code I use;

use Errno 'EINTR'; # or use a constant value of 4

ClientAccept: {
$client = $server->accept();
if ($! == EINTR) {
if ($client) {
print "Non-fatal Interrupted system call in accept()\n";
} else {
print "Interrupted system call - redo accept()\n";
redo ClientAccept;
}
}

# --- rest of your server-code
}

Good luck,
Stefan


Thanks Stefan.
I'll check your proposal.

Sébastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top