X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FDS.pm;fp=lib%2FPublicInbox%2FDS.pm;h=ba6c74d0ea97d51e069a85bdef6ad3123cc7e4d5;hp=37cd6087cafb2bd8009921f86c27d7de741c6125;hb=1c52f49354aa83e71fcceccae888da0c77f2391d;hpb=5824d0d4ffac120a2840c980b4570868d6b3ea6b diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 37cd6087..ba6c74d0 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -155,13 +155,6 @@ sub _InitPoller } } -=head2 C<< CLASS->EventLoop() >> - -Start processing IO events. In most daemon programs this never exits. See -C below for how to exit the loop. - -=cut - sub now () { clock_gettime(CLOCK_MONOTONIC) } sub next_tick () { @@ -277,26 +270,41 @@ sub PostEventLoop () { $PostLoopCallback ? $PostLoopCallback->(\%DescriptorMap) : 1; } -sub EventLoop { - $Epoll //= _InitPoller(); - local $in_loop = 1; - my @events; - do { - my $timeout = RunTimers(); - - # get up to 1000 events - epoll_wait($Epoll, 1000, $timeout, \@events); - for my $fd (@events) { - # it's possible epoll_wait returned many events, including some at the end - # that ones in the front triggered unregister-interest actions. if we - # can't find the %sock entry, it's because we're no longer interested - # in that event. - - # guard stack-not-refcounted w/ Carp + @DB::args - my $obj = $DescriptorMap{$fd}; - $obj->event_step; - } - } while (PostEventLoop()); +# Start processing IO events. In most daemon programs this never exits. See +# C for how to exit the loop. +sub event_loop (;$$) { + my ($sig, $oldset) = @_; + $Epoll //= _InitPoller(); + require PublicInbox::Sigfd if $sig; + my $sigfd = PublicInbox::Sigfd->new($sig, 1) if $sig; + local @SIG{keys %$sig} = values(%$sig) if $sig && !$sigfd; + local $SIG{PIPE} = 'IGNORE'; + if (!$sigfd && $sig) { + # wake up every second to accept signals if we don't + # have signalfd or IO::KQueue: + sig_setmask($oldset); + PublicInbox::DS->SetLoopTimeout(1000); + } + $_[0] = $sigfd = $sig = undef; # $_[0] == sig + local $in_loop = 1; + my @events; + do { + my $timeout = RunTimers(); + + # get up to 1000 events + epoll_wait($Epoll, 1000, $timeout, \@events); + for my $fd (@events) { + # it's possible epoll_wait returned many events, + # including some at the end that ones in the front + # triggered unregister-interest actions. if we can't + # find the %sock entry, it's because we're no longer + # interested in that event. + + # guard stack-not-refcounted w/ Carp + @DB::args + my $obj = $DescriptorMap{$fd}; + $obj->event_step; + } + } while (PostEventLoop()); } =head2 C<< CLASS->SetPostLoopCallback( CODEREF ) >> @@ -326,7 +334,7 @@ sub SetPostLoopCallback { =head2 C<< CLASS->new( $socket ) >> Create a new PublicInbox::DS subclass object for the given I which will -react to events on it during the C. +react to events on it during the C. This is normally (always?) called from your subclass via: