in reply to Re: waking from select, or IO::Pipe in same process?
in thread waking from select, or IO::Pipe in same process?

Hmm, it looks like IO::Socket::INET's accept already does something with signals. If I install an empty signal handler at the top level, then accept() returns undef cleanly. The perlipc docs show an example of checking for EINTR in this case. I haven't tested IO::Select yet, but I'd assume it behaves the same.

Chris

  • Comment on Re^2: waking from select, or IO::Pipe in same process?

Replies are listed 'Best First'.
Re^3: waking from select, or IO::Pipe in same process?
by ikegami (Patriarch) on Jul 15, 2011 at 18:09 UTC
    IO::Select is just a thin wrapper around select. accept and select are just thin wrapper around the system calls with the same name. They should return error EINTR when interrupted by a signal (which will only happen if you have a signal handler defined).

      Ah, somehow I missed that in my reading about how to do this. If that's the case, I don't need the pipe at all, which is nice.

      Thanks!
      Chris

        $ perl -E' $SIG{INT} = sub { if ($i++) { say "You were sure."; exit(1); } else { say "Are you sure?"; } }; for (;;) { say "Waiting..."; if (select(undef, undef, undef, undef) < 0) { if ($!{EINTR}) { say "Interrupted"; } else { die $!; } } else { say "select returned without an error???"; } } ' Waiting... ^CAre you sure? Interrupted Waiting... ^CYou were sure.