diff options
author | Eric Wong <e@80x24.org> | 2023-11-02 09:35:33 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-11-03 06:39:30 +0000 |
commit | cfe25e6aa966144a9c96d1ba2c301fd5e1bad79b (patch) | |
tree | 4faa9092c422aafca9568e547634096da12667e9 /lib/PublicInbox/Git.pm | |
parent | 16957ad7c4edcbf43294e67c8db06167594f0660 (diff) | |
download | public-inbox-cfe25e6aa966144a9c96d1ba2c301fd5e1bad79b.tar.gz |
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.
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r-- | lib/PublicInbox/Git.pm | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 3dac32be..d00f576e 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -18,7 +18,7 @@ use Errno qw(EINTR EAGAIN); use File::Glob qw(bsd_glob GLOB_NOSORT); use File::Spec (); use PublicInbox::Spawn qw(spawn popen_rd run_qx which); -use PublicInbox::ProcessIONBF; +use PublicInbox::IO; use PublicInbox::Tmpfile; use IO::Poll qw(POLLIN); use Carp qw(croak carp); @@ -146,6 +146,7 @@ sub _sock_cmd { my ($self, $batch, $err_c) = @_; $self->{sock} and Carp::confess('BUG: {sock} exists'); socketpair(my $s1, my $s2, AF_UNIX, SOCK_STREAM, 0); + $s1->blocking(0); my $opt = { pgid => 0, 0 => $s2, 1 => $s2 }; my $gd = $self->{git_dir}; if ($gd =~ s!/([^/]+/[^/]+)\z!/!) { @@ -164,7 +165,7 @@ sub _sock_cmd { $self->fail("tmpfile($id): $!"); } my $pid = spawn(\@cmd, undef, $opt); - $self->{sock} = PublicInbox::ProcessIONBF->new($pid, $s1); + $self->{sock} = PublicInbox::IO::attach_pid($s1, $pid); } sub poll_in ($) { IO::Poll::_poll($RDTIMEO, fileno($_[0]), my $ev = POLLIN) } @@ -638,8 +639,7 @@ sub cleanup_if_unlinked { my $ret = 0; for my $obj ($self, ($self->{ck} // ())) { my $sock = $obj->{sock} // next; - my PublicInbox::ProcessIONBF $p = tied *$sock; # ProcessIONBF - my $pid = $p->{pid} // next; + my $pid = $sock->attached_pid // next; open my $fh, '<', "/proc/$pid/maps" or return cleanup($self, 1); while (<$fh>) { # n.b. we do not restart for unlinked multi-pack-index |