diff options
author | Eric Wong <e@80x24.org> | 2016-04-25 05:12:43 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-04-25 05:26:37 +0000 |
commit | 85c83085eeb14be7e7b9a395fa9408241ecb8244 (patch) | |
tree | 7d80b6731a157d0f016919ffdaa86c5f2d1f08a6 /lib/PublicInbox/HTTPD/Async.pm | |
parent | 837323706d89660923ac2aed21f07f12ad80be72 (diff) | |
download | public-inbox-85c83085eeb14be7e7b9a395fa9408241ecb8244.tar.gz |
Hopefully this modularizes things a little and allows us to work on a combined super server to save RAM.
Diffstat (limited to 'lib/PublicInbox/HTTPD/Async.pm')
-rw-r--r-- | lib/PublicInbox/HTTPD/Async.pm | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm new file mode 100644 index 00000000..63985026 --- /dev/null +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -0,0 +1,35 @@ +# Copyright (C) 2016 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +# +# XXX This is a totally unstable API for public-inbox internal use only +# This is exposed via the 'pi-httpd.async' key in the PSGI env hash. +# The name of this key is not even stable! +# Currently is is intended for use with read-only pipes. +package PublicInbox::HTTPD::Async; +use strict; +use warnings; +use base qw(Danga::Socket); +use fields qw(cb); + +sub new { + my ($class, $io, $cb) = @_; + my $self = fields::new($class); + IO::Handle::blocking($io, 0); + $self->SUPER::new($io); + $self->{cb} = $cb; + $self->watch_read(1); + $self; +} + +sub event_read { $_[0]->{cb}->() } +sub event_hup { $_[0]->{cb}->() } +sub event_err { $_[0]->{cb}->() } +sub sysread { shift->{sock}->sysread(@_) } + +sub close { + my $self = shift; + $self->{cb} = undef; + $self->SUPER::close(@_); +} + +1; |