1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # XXX This is a totally unstable API for public-inbox internal use only
5 # This is exposed via the 'pi-httpd.async' key in the PSGI env hash.
6 # The name of this key is not even stable!
7 # Currently is is intended for use with read-only pipes.
8 package PublicInbox::HTTPD::Async;
11 use base qw(Danga::Socket);
15 my ($class, $io, $cb) = @_;
16 my $self = fields::new($class);
17 IO::Handle::blocking($io, 0);
18 $self->SUPER::new($io);
24 sub async_pass { $_[0]->{cb} = $_[1] }
25 sub event_read { $_[0]->{cb}->() }
26 sub event_hup { $_[0]->{cb}->() }
27 sub event_err { $_[0]->{cb}->() }
28 sub sysread { shift->{sock}->sysread(@_) }
29 sub getline { $_[0]->{sock}->getline };
34 $self->SUPER::close(@_);
37 # do not let ourselves be closed during graceful termination
38 sub busy () { $_[0]->{cb} }