about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-06-30 03:54:26 +0000
committerEric Wong <e@80x24.org>2019-06-30 04:00:54 +0000
commitd20a122c48a274e224d5c1a8d0f943ae395cff2a (patch)
tree900efd2c383f1684c70f041dc0c60722636f0fe9
parent8ef878ebc6f9f3a337341a3aa42a84fc190032a3 (diff)
downloadpublic-inbox-d20a122c48a274e224d5c1a8d0f943ae395cff2a.tar.gz
Since we have EPOLL_CTL_DEL implemented for the poll(2) and
kqueue backends, we can rely on Perl refcounting to gently
close(2) the underlying file descriptors as references get
dropped.

This may be beneficial in the future if we want to drop a
descriptor from the event loop without actually closing it.
-rw-r--r--lib/PublicInbox/DS.pm13
1 files changed, 2 insertions, 11 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index a8236023..57c42063 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -259,17 +259,8 @@ 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};
-    }
-
+    delete($DescriptorMap{fileno($_)}) for @ToClose;
+    @ToClose = (); # let refcounting drop everything all at once
 
     # by default we keep running, unless a postloop callback (either per-object
     # or global) cancels it