in reply to SIGCHLD interrupting accept call?

In Solaris 7, accept() is not restarted automatically. I found that out the hard way in a project I'm working on. This seems to work for me:
## Infinite loop while(1) { for($waitepid = 0; ($clientaddr = accept(SOCK_CLNT,SOCK_SRV) || $wai +tepid); $waitepid = 0, close(SOCK_CLNT)) { next if $waitepid and not $clientaddr; ## do things... } }
HTH! /dempa

PS. BTW, this is my first post here. :)

Replies are listed 'Best First'.
RE: Re: SIGCHLD interrupting accept call?
by ZZamboni (Curate) on May 09, 2000 at 17:25 UTC
    Thanks! This works perfectly. That for statement goes to my Perl bag-o-tricks :-)

    The only thing that took me a couple of minutes was how to assign the value of $waitepid. Because here's what I had in my signal handler:

    sub REAPER { my $stiff; while ($stiff=waitpid(-1,WNOHANG)>0) { } }
    Simply replacing $stiff with $waitepid and making it global would not have worked, since the loop is waiting until it is zero or less than zero. So here's what I did:
    sub REAPER { my $stiff; while ($stiff=waitpid(-1,WNOHANG)>0) { $waitepid+=$stiff; } }
    Which gives the appropriate effect. However, I'm wondering now if there is a better way of doing it. Any ideas?

    Thanks a lot!

    --ZZamboni