From 85c83085eeb14be7e7b9a395fa9408241ecb8244 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 25 Apr 2016 05:12:43 +0000 Subject: split out NNTPD and HTTPD* modules Hopefully this modularizes things a little and allows us to work on a combined super server to save RAM. --- lib/PublicInbox/HTTPD/Async.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/PublicInbox/HTTPD/Async.pm (limited to 'lib/PublicInbox/HTTPD') 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 +# License: AGPL-3.0+ +# +# 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; -- cgit v1.2.3-24-ge0c7