From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0F54C1F461 for ; Sun, 30 Jun 2019 04:12:51 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] ds: rely on refcounting to close descriptors Date: Sun, 30 Jun 2019 04:12:51 +0000 Message-Id: <20190630041251.4222-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/DS.pm | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index a823602..57c4206 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 -- EW