use warnings;
use base qw(Danga::Socket);
use fields qw(cb cleanup);
+use Scalar::Util qw(weaken);
require PublicInbox::EvCleanup;
sub new {
$self;
}
+sub restart_read_cb ($) {
+ my ($self) = @_;
+ sub { $self->watch_read(1) }
+}
+
sub async_pass {
my ($self, $io, $fh, $bref) = @_;
- my $restart_read = sub { $self->watch_read(1) };
# In case the client HTTP connection ($io) dies, it
# will automatically close this ($self) object.
$io->{forward} = $self;
$fh->write($$bref);
+ my $restart_read = restart_read_cb($self);
+ weaken($self);
$self->{cb} = sub {
my $r = sysread($self->{sock}, $$bref, 8192);
if ($r) {
$self->watch_read(0);
$io->write($restart_read); # D::S::write
}
- return; # stay in watch_read
+ # stay in watch_read, but let other clients
+ # get some work done, too.
+ return;
} elsif (!defined $r) {
return if $!{EAGAIN} || $!{EINTR};
}
PublicInbox::EvCleanup::asap($cleanup) if $cleanup;
}
-# do not let ourselves be closed during graceful termination
-sub busy () { $_[0]->{cb} }
-
1;