-# Internal function: run the post-event callback, send read events
-# for pushed-back data, and close pending connections. returns 1
-# if event loop should continue, or 0 to shut it all down.
-sub PostEventLoop {
- # now we can close sockets that wanted to close during our event processing.
- # (we didn't want to close them during the loop, as we didn't want fd numbers
- # being reused and confused during the event loop)
- while (my $sock = shift @ToClose) {
- my $fd = fileno($sock);
-
- # close the socket. (not a PublicInbox::DS close)
- CORE::close($sock);
-
- # and now we can finally remove the fd from the map. see
- # comment above in ->close.
- delete $DescriptorMap{$fd};
- }
-
-
- # by default we keep running, unless a postloop callback (either per-object
- # or global) cancels it
- my $keep_running = 1;
-
- # now we're at the very end, call callback if defined
- if (defined $PostLoopCallback) {
- $keep_running &&= $PostLoopCallback->(\%DescriptorMap);
- }
-
- return $keep_running;
-}
-
-# map EPOLL* bits to kqueue EV_* flags for EV_SET
-sub kq_flag ($$) {
- my ($bit, $ev) = @_;
- if ($ev & $bit) {
- my $fl = EV_ADD() | EV_ENABLE();
- ($ev & EPOLLONESHOT) ? ($fl|EV_ONESHOT()) : $fl;
- } else {
- EV_ADD() | EV_DISABLE();
- }
-}
-