in reply to Catching a signal causes my socket server to die

Using a SIGALRM handler seems to not work because it causes accept() to return.

Doesn't the same thing happen with SIGUSR1? If so, just loop back if the error was EINTR.

use Errno qw( EINTR ); do { while (my $client = $sock->accept()) { ... } } while ($! == EINTR);

Replies are listed 'Best First'.
Re^2: Catching a signal causes my socket server to die
by jimmy5804 (Initiate) on Jan 07, 2009 at 20:56 UTC
    My understanding is that accept() returns on SIGALRM because it uses sleep() internally which uses SIGALRM in it's implementation - so you basically have two SIGALRM handlers. I had hoped that I could avoid this with SIGUSR1, but.... apparently not.
      accept is a system call. It doesn't use sleep, a different system call. Mind you, both put the process in a sleep state, and both are reactive to signals. Any signals, not just ALRM.
Re^2: Catching a signal causes my socket server to die
by jimmy5804 (Initiate) on Jan 07, 2009 at 21:31 UTC
    By the way, I found the accept() loop in the 3rd party server module I was using and modified it. It works, it's a generally applicable piece of knowledge for me, and it seems like the right solution for my problem. Thanks much!