From 617f35dacbd4e5972bf2d82411b45009bbc79a42 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 27 Feb 2016 21:31:24 +0000 Subject: git: use built-in spawn implementation for vfork This should reduce overhead of spawning git processes from our long-running httpd and nntpd servers. --- lib/PublicInbox/ProcessPipe.pm | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/PublicInbox/ProcessPipe.pm (limited to 'lib/PublicInbox/ProcessPipe.pm') 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 +# License: AGPL-3.0+ + +# 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; -- cgit v1.2.3-24-ge0c7