NAME
UniEvent::Signal - runs callbacks upon UNIX signals
SYNOPSIS
use UniEvent::Signal; # for constants
my $loop = UniEvent::Loop->new;
# handy way
my $h = UniEvent::Signal::watch(SIGINT, sub { say "got SIGINT" }, $loop);
# more verbose way
my $h = UniEvent::Signal->new($loop);
$h->start(SIGINT, sub {
my ($h, $signal) = @_;
say "got signal $signal";
});
$loop->run;
# one shot signal watcher
$h->once(SIGTERM);
DESCRIPTION
Allow to check UNIX signals and, if a signal appears, execute approprate handlers during loop iteration. One callback is capable to handle multiple signals if needed.
It is inherited from UniEvent::Handle.
FUNCTIONS
watch($signal, $callback [, $loop = UniEvent::Loop->default_loop])
Handy function which creates handler, sets the $callback
and marks the $signal
for permanent watching for the next event loop iterations.
Returns the signal handler.
METHODS
new([$loop = UniEvent::Loop->default_loop])
Constructs new Signal handle and binds it to the specified event loop.
start($signal, [$callback = undef])
Marks $signal
to be permanently handled in the next event loop iterations. Optionally it adds the $callback
to the existing event listeners.
stop()
Stops the singal handle, i.e. makes it inactive for the next event loop iteration.
callback($code)
Sets the callback, which will be invoked upon the interested signals. All previously set event listeners or callbacks are discarded.
event()
Returns XS::Framework::CallbackDispatcher instance, where callback(s) can be assigned with. The callbacks will be invoked upon signal in loop iteration.
The C++ interface is:
void(const SignalSP& handle, int signum)
On perl side it the callbacks will be called:
$callback->($handle, $signal);
Multiple callbacks can be added via the XS::Framework::CallbackDispatcher interface.
event_listener($delegate [, $weak = false])
Creates and returns wrapper around the $delegate
object of arbitrary class, having the following methods:
$delegate->on_signal($handle, $signal);
The delegated object can be seen as alternative of setting indivitual callbacks or as a way of groupping them. The $delegate
object can optionally be weakened.
call_now($signal)
Immediately ivokes assigned callbacks and listeners in the caller context (i.e. not waiting loop run) with the given signal.
once($signal [, $callback = undef])
Temporally marks $signal
to be watched in the next event loop iteration(s). Upon $signal
receiving, callback will no longer watch for it.
Optionally it adds the $callback
to the existing event listeners.
CONSTANTS
SIGNAL NAMES
Some signals might be not available for particular platforms.
SIGINT
SIGILL
SIGABRT
SIGFPE
SIGSEGV
SIGTERM
SIGHUP
SIGQUIT
SIGTRAP
SIGBUS
SIGKILL
SIGUSR1
SIGUSR2
SIGPIPE
SIGALRM
SIGSTKFLT
SIGCHLD
SIGCONT
SIGSTOP
SIGTSTP
SIGTTIN
SIGTTOU
SIGURG
SIGXCPU
SIGXFSZ
SIGVTALRM
SIGPROF
SIGWINCH
SIGIO
SIGPOLL
SIGPWR
SIGSYS
TYPE
Signal type constant