package PublicInbox::GitAsyncCat;
use v5.12;
use parent qw(PublicInbox::DS Exporter);
+use PublicInbox::DS qw(awaitpid);
use POSIX qw(WNOHANG);
use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
our @EXPORT = qw(ibx_async_cat ibx_async_prefetch async_check);
$self->SUPER::close; # PublicInbox::DS::close
}
+sub aclose { $_[1]->close } # ignore PID ($_[0])
+
sub event_step {
my ($self) = @_;
my $git = $self->{git} or return;
# ok, more to do, requeue for fairness
$self->requeue;
}
- } elsif ((my $pid = waitpid($git->{pid}, WNOHANG)) > 0) {
- # May happen if the child process is killed by a BOFH
- # (or segfaults)
- delete $git->{pid};
- warn "E: git $pid exited with \$?=$?\n";
- $self->close;
}
}
my $self = bless { git => $git }, __PACKAGE__;
$git->{in}->blocking(0);
$self->SUPER::new($git->{in}, EPOLLIN|EPOLLET);
+ awaitpid($git->{pid}, \&aclose, $self);
\undef; # this is a true ref()
};
}
my ($ibx, $oidish, $cb, $arg) = @_; # $ibx may be $ctx
my $git = $ibx->{git} // $ibx->git;
$git->check_async($oidish, $cb, $arg);
+ return watch_cat($git) if $git->{-bc}; # --batch-command
$git->{async_chk} //= do {
my $self = bless { git => $git }, 'PublicInbox::GitAsyncCheck';
$git->{in_c}->blocking(0);
$self->SUPER::new($git->{in_c}, EPOLLIN|EPOLLET);
+ awaitpid($git->{pid_c}, \&aclose, $self);
\undef; # this is a true ref()
};
}
$oid .= " $git->{git_dir}\n";
return $GCF2C->gcf2_async(\$oid, $cb, $arg); # true
}
- } elsif ($git->{async_cat} && (my $inflight = $git->{inflight})) {
- if (!@$inflight) {
- print { $git->{out} } $oid, "\n" or
- $git->fail("write error: $!");
- return push(@$inflight, $oid, $cb, $arg);
- }
+ } elsif ($git->{async_cat}) {
+ return $git->async_prefetch($oid, $cb, $arg);
}
undef;
}
# ok, more to do, requeue for fairness
$self->requeue;
}
- } elsif ((my $pid = waitpid($git->{pid_c}, WNOHANG)) > 0) {
- # May happen if the child process is killed by a BOFH
- # (or segfaults)
- delete $git->{pid_c};
- warn "E: git $pid exited with \$?=$?\n";
- $self->close;
}
}