about summary refs log tree commit homepage
path: root/lib/PublicInbox/EOFpipe.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-08-31 04:41:38 +0000
committerEric Wong <e@80x24.org>2020-09-01 00:19:19 +0000
commit5fa34fad91d262f446465772dce9ac3dde9673bf (patch)
treea76bfdc866962b51e69bb24ba513f36b3f0efbda /lib/PublicInbox/EOFpipe.pm
parent8aec4e8ddea9d9002be2d6af0849d8c5eb84b2e7 (diff)
downloadpublic-inbox-5fa34fad91d262f446465772dce9ac3dde9673bf.tar.gz
It's a bit inefficient to use a pipe, here.  However, using
dwaitpid() on a process that's not expected to exit soon is
also inefficient as it causes excessive wakeups as most of
our inbox-writing code expects synchronous waitpid().

This only affects -watch instances configured for NNTP and IMAP
clients.
Diffstat (limited to 'lib/PublicInbox/EOFpipe.pm')
-rw-r--r--lib/PublicInbox/EOFpipe.pm24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/PublicInbox/EOFpipe.pm b/lib/PublicInbox/EOFpipe.pm
new file mode 100644
index 00000000..489caf82
--- /dev/null
+++ b/lib/PublicInbox/EOFpipe.pm
@@ -0,0 +1,24 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+package PublicInbox::EOFpipe;
+use strict;
+use parent qw(PublicInbox::DS);
+use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
+
+sub new {
+        my (undef, $rd, $cb, $arg) = @_;
+        my $self = bless {  cb => $cb, arg => $arg }, __PACKAGE__;
+        # 1031: F_SETPIPE_SZ, 4096: page size
+        fcntl($rd, 1031, 4096) if $^O eq 'linux';
+        $self->SUPER::new($rd, EPOLLIN|EPOLLONESHOT);
+}
+
+sub event_step {
+        my ($self) = @_;
+        if ($self->do_read(my $buf, 1) == 0) { # auto-closed
+                $self->{cb}->($self->{arg});
+        }
+}
+
+1;