[Israel.pm] receiving undef via socket
Gabor Szabo
szabgab at gmail.com
Thu Aug 3 03:01:27 PDT 2006
I am lost at this.
I have an application that is forking clients and talks to them via sockets.
Ocassionally the client receives undef via the socket. I wonder why.
Here is the code, more or less, cut from the real code.
Any ideas ?
(Oh and it is currently running on on AIX and perl 5.6.1)
socketpair($sock_to_child, $sock_to_parent, AF_UNIX, SOCK_STREAM,
PF_UNSPEC) or die;
$sock_to_child->autoflush(1);
$sock_to_parent->autoflush(1);
# block signal for fork
my $sigset = POSIX::SigSet->new(SIGINT);
sigprocmask(SIG_BLOCK, $sigset) or die;
if (my $pid = fork) { # in parent
sigprocmask(SIG_UNBLOCK, $sigset) or die;
close $sock_to_parent;
while($msg = get_command()) {
if (not print $child_socket "$msg\n") {
warn "Could not send $msg";
}
}
} elsif (not defined $pid) {
die;
} else { #child
$SIG{INT} = 'DEFAULT';
$SIG{CHLD} = 'DEFAULT';
sigprocmask(SIG_UNBLOCK, $sigset) or die;
close $sock_to_child;
while(1) {
my $msg = <$sock_to_parent>;
if (not defined $msg) {
# Why, Oh why do I get here ocassionally?
exit;
}
# does some clever thing with the
print $sock_to_parent "done\n";
}
exit;
}
More information about the Perl
mailing list