POE signal handling

Torsten Foertsch <[email protected]>
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
Hi,

I am quite new to POE. So, please forgive a silly question.

What is the best way to implement process global signal handling?

What I have done so far is this:

POE::Session->create
  ( inline_states =>
    { _start         => \&server_start,
      _stop          => sub {},
      got_signal     => sub {
	warn "got signal ".$_[ARG0]."\n";
	$_[KERNEL]->sig_handled;
      },
      got_quit       => sub {
	warn "got signal ".$_[ARG0]."\n";
	$_[KERNEL]->sig_handled;
	$_[KERNEL]->post(main_server=>'shutdown');
      },
    },
  );

sub server_start {
  POE::Component::Server::TCP->new
      ( Alias => 'main_server',
        Port => 12345,
	Address => 'localhost',
	ClientInput => sub {
	  my ( $heap, $input ) = @_[ HEAP, ARG0 ];
	  $heap->{client}->put($input);
	},
      );
  $_[KERNEL]->sig(INT =>'got_signal');
  $_[KERNEL]->sig(HUP =>'got_signal');
  $_[KERNEL]->sig(TERM=>'got_signal');
  $_[KERNEL]->sig(QUIT=>'got_quit');
  $_[KERNEL]->alias_set('sighandler');
}

POE::Kernel->run();

What I want to be sure is that an asynchronous signal doesn't kill the 
process nevertheless when it arrives. The program creates one session 
and in the _start handler creates another one within PoCo::Server::TCP, 
right? So, the second session is a child session of the first one.

Is it possible to have N sessions that are direct children of the kernel 
and dedicate one of them to unix signal handling? Something like this:

POE::Session->create
  ( inline_states =>
    { _start         => sub {
        $_[KERNEL]->sig(INT =>'got_signal');
        $_[KERNEL]->sig(HUP =>'got_signal');
        $_[KERNEL]->sig(TERM=>'got_signal');
        $_[KERNEL]->sig(QUIT=>'got_quit');
        $_[KERNEL]->alias_set('sighandler');
      },
      _stop          => sub {},
      got_signal     => sub {
	warn "got signal ".$_[ARG0]."\n";
	$_[KERNEL]->sig_handled;
      },
      got_quit       => sub {
	warn "got signal ".$_[ARG0]."\n";
	$_[KERNEL]->sig_handled;
	$_[KERNEL]->post(main_server=>'shutdown');
      },
    },
  );

POE::Component::Server::TCP->new
      ( Alias => 'main_server',
        Port => 12345,
	Address => 'localhost',
	ClientInput => sub {
	  my ( $heap, $input ) = @_[ HEAP, ARG0 ];
	  $heap->{client}->put($input);
	},
      );

POE::Kernel->run();

Can I be sure that a SIGINT is routed to the sighandler session even if 
the process is currently busy processing input/output for main_server?

Thanks,
Torsten
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.