From cfe25e6aa966144a9c96d1ba2c301fd5e1bad79b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Nov 2023 09:35:33 +0000 Subject: replace ProcessIO with untied PublicInbox::IO This fixes two major problems with the use of tie for filehandles: * no way to do fcntl, stat, etc. calls directly on the tied handle, forcing callers to use the `tied' perlop to access the underlying IO::Handle * needing separate classes to handle blocking and non-blocking I/O As a result, Git->cleanup_if_unlinked, InputPipe->consume, and Qspawn->_yield_start have fewer bizzare bits and we can call `$io->blocking(0)' directly instead of `(tied *$io)->{fh}->blocking(0)' Having a PublicInbox::IO class will also allow us to support custom read buffering which allows inspecting the current state. --- lib/PublicInbox/Spawn.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/Spawn.pm') diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index b4f37bea..d3b7ef6f 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -19,7 +19,7 @@ use PublicInbox::Lock; use Fcntl qw(SEEK_SET); use IO::Handle (); use Carp qw(croak); -use PublicInbox::ProcessIO; +use PublicInbox::IO; our @EXPORT_OK = qw(which spawn popen_rd popen_wr run_die run_wait run_qx); our @RLIMITS = qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA); use autodie qw(open pipe seek sysseek truncate); @@ -377,7 +377,7 @@ sub popen_rd { my ($cmd, $env, $opt, @cb_arg) = @_; pipe(my $r, local $opt->{1}); my $pid = spawn($cmd, $env, $opt); - PublicInbox::ProcessIO->maybe_new($pid, $r, @cb_arg); + wantarray ? ($r, $pid) : PublicInbox::IO::attach_pid($r, $pid, @cb_arg) } sub popen_wr { @@ -385,7 +385,7 @@ sub popen_wr { pipe(local $opt->{0}, my $w); $w->autoflush(1); my $pid = spawn($cmd, $env, $opt); - PublicInbox::ProcessIO->maybe_new($pid, $w, @cb_arg) + wantarray ? ($w, $pid) : PublicInbox::IO::attach_pid($w, $pid, @cb_arg) } sub read_out_err ($) { -- cgit v1.2.3-24-ge0c7