[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;


# 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) {
} else { #child

    $SIG{INT}  = '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?
       # does some clever thing with the
       print $sock_to_parent "done\n";

More information about the Perl mailing list