user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/6] watch: simplify DirIdle object cleanup
Date: Tue, 31 Oct 2023 20:42:53 +0000	[thread overview]
Message-ID: <20231031204255.1837649-5-e@80x24.org> (raw)
In-Reply-To: <20231031204255.1837649-1-e@80x24.org>

There's no need to waste time nor reach into DS internals to
map FDs to Perl objects, here.  LEI.pm has never had to deal
with integer FDs for DirIdle, either.
---
 lib/PublicInbox/Watch.pm | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 41b77dc1..c2b1312a 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -256,9 +256,8 @@ sub quit { # may be called in IMAP/NNTP children
 	%{$self->{opendirs}} = ();
 	_done_for_now($self);
 	quit_done($self);
-	if (defined(my $fd = delete $self->{dir_idle_fd})) {
-		my $di = $PublicInbox::DS::DescriptorMap{$fd};
-		$di->close if $di && $di->can('add_watches');
+	if (my $dir_idle = delete $self->{dir_idle}) {
+		$dir_idle->close if $dir_idle;
 	}
 	if (my $idle_mic = delete $self->{idle_mic}) { # IMAP child
 		return unless $idle_mic->IsConnected && $idle_mic->Socket;
@@ -283,8 +282,7 @@ sub watch_fs_init ($) {
 	};
 	require PublicInbox::DirIdle;
 	# inotify_create + EPOLL_CTL_ADD
-	my $dir_idle = PublicInbox::DirIdle->new($cb);
-	$self->{dir_idle_fd} = fileno($dir_idle->{sock}) if $dir_idle->{sock};
+	my $dir_idle = $self->{dir_idle} = PublicInbox::DirIdle->new($cb);
 	$dir_idle->add_watches([keys %{$self->{mdmap}}]);
 }
 
@@ -383,8 +381,7 @@ sub watch_imap_idle_1 ($$$) {
 
 sub watch_atfork_child ($) {
 	my ($self) = @_;
-	delete $self->{pids};
-	delete $self->{opendirs};
+	delete @$self{qw(dir_idle pids opendirs)};
 	my $sig = delete $self->{sig};
 	$sig->{CHLD} = $sig->{HUP} = $sig->{USR1} = 'DEFAULT';
 	# TERM/QUIT/INT call ->quit, which works in both parent+child

  parent reply	other threads:[~2023-10-31 20:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 20:42 [PATCH 0/6] ds: object lifetime shortening Eric Wong
2023-10-31 20:42 ` [PATCH 1/6] ds: next_tick: shorten object lifetimes Eric Wong
2023-10-31 20:42 ` [PATCH 2/6] ds: do not defer close Eric Wong
2023-10-31 20:42 ` [PATCH 3/6] ds: move maxevents further down the stack Eric Wong
2023-10-31 20:42 ` Eric Wong [this message]
2023-10-31 20:42 ` [PATCH 5/6] pop3: use SSL_shutdown(3ssl) if appropriate Eric Wong
2023-10-31 20:42 ` [PATCH 6/6] ds: make ->close behave like CORE::close Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231031204255.1837649-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).