diff options
author | Eric Wong <e@80x24.org> | 2016-02-27 21:31:24 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-02-27 21:51:39 +0000 |
commit | 617f35dacbd4e5972bf2d82411b45009bbc79a42 (patch) | |
tree | 0a763db89c81941f16dbd16761a35602f3c723c9 /lib/PublicInbox/ProcessPipe.pm | |
parent | ca885bd5905b7faa9ecb7b0eb02476de1d3a7f88 (diff) | |
download | public-inbox-617f35dacbd4e5972bf2d82411b45009bbc79a42.tar.gz |
This should reduce overhead of spawning git processes from our long-running httpd and nntpd servers.
Diffstat (limited to 'lib/PublicInbox/ProcessPipe.pm')
-rw-r--r-- | lib/PublicInbox/ProcessPipe.pm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm new file mode 100644 index 00000000..eade524c --- /dev/null +++ b/lib/PublicInbox/ProcessPipe.pm @@ -0,0 +1,30 @@ +# Copyright (C) 2016 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> + +# a tied handle for auto reaping of children tied to a pipe, see perltie(1) +package PublicInbox::ProcessPipe; +use strict; +use warnings; + +sub TIEHANDLE { + my ($class, $pid, $fh) = @_; + bless { pid => $pid, fh => $fh }, $class; +} + +sub READ { sysread($_[0]->{fh}, $_[1], $_[2], $_[3] || 0) } + +sub READLINE { readline($_[0]->{fh}) } + +sub CLOSE { close($_[0]->{fh}) } + +sub FILENO { fileno($_[0]->{fh}) } + +sub DESTROY { + my $fh = delete($_[0]->{fh}); + close $fh if $fh; + waitpid($_[0]->{pid}, 0); +} + +sub pid { $_[0]->{pid} } + +1; |