1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # internal class used by PublicInbox::Git + Danga::Socket
5 # This parses the output pipe of "git cat-file --batch"
7 # Note: this does NOT set the non-blocking flag, we expect `git cat-file'
8 # to be a local process, and git won't start writing a blob until it's
9 # fully read. So minimize context switching and read as much as possible
10 # and avoid holding a buffer in our heap any longer than it has to live.
11 package PublicInbox::GitAsyncCat;
13 use parent qw(PublicInbox::DS Exporter);
15 use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
16 our @EXPORT = qw(git_async_cat);
19 my ($class, $git) = @_;
20 my $self = fields::new($class);
22 $self->SUPER::new($git->{in}, EPOLLIN|EPOLLET);
29 my $git = $self->{git} or return; # ->close-ed
30 my $inflight = $git->{inflight};
32 $git->cat_async_step($inflight);
33 $self->requeue if @$inflight || exists $git->{cat_rbuf};
39 if (my $git = delete $self->{git}) {
40 delete $git->{async_cat}; # drop circular reference
42 $self->SUPER::close; # PublicInbox::DS::close
45 sub git_async_cat ($$$$) {
46 my ($git, $oid, $cb, $arg) = @_;
47 $git->cat_async($oid, $cb, $arg);
48 $git->{async_cat} //= new(__PACKAGE__, $git); # circular reference