Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Very first pass at signal handlers.
Probably some we could support are missing (though it's an LHF for
somebody to add those), and the API is certainly up for discussion.
But now there is, at least, a way. Closing the tap doesn't in any
way remove the handler yet; that'll come later once the more general
cancellation mechanism arrives.
  • Loading branch information
jnthn committed Apr 20, 2014
1 parent 327e9dc commit 0b1f8aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/signals.pm
@@ -0,0 +1,20 @@
my enum Signal ( :SIGINT(1), :SIGBREAK(2), :SIGHUP(3), :SIGWINCH(4) );

sub signal(*@signals, :$scheduler = $*SCHEDULER) {
my class SignalCancellation is repr('AsyncTask') { }
state %sigmap =
SIGINT, nqp::const::SIG_INT,
SIGBREAK, nqp::const::SIG_BREAK,
SIGHUP, nqp::const::SIG_HUP,
SIGWINCH, nqp::const::SIG_WINCH;
my @supplies = @signals.map(-> $sig {
die "Invalid signal" unless $sig ~~ Signal;
my $s = Supply.new;
nqp::signal($scheduler.queue,
-> $signum { $s.more($signum) },
nqp::unbox_i(%sigmap{$sig}),
SignalCancellation);
$s
});
@supplies == 1 ?? @supplies[0] !! Supply.merge(@supplies)
}
1 change: 1 addition & 0 deletions tools/build/Makefile-Moar.in
Expand Up @@ -165,6 +165,7 @@ M_CORE_SOURCES = \
src/core/Supply.pm \
src/core/SupplyOperations.pm \
src/core/asyncops.pm \
src/core/signals.pm \
src/core/IO/Socket.pm \
src/core/IO/Socket/INET.pm \
src/core/OS.pm \
Expand Down

0 comments on commit 0b1f8aa

Please sign in to comment.