about summary refs log tree commit homepage
path: root/public-inbox-httpd
diff options
context:
space:
mode:
Diffstat (limited to 'public-inbox-httpd')
-rw-r--r--public-inbox-httpd32
1 files changed, 32 insertions, 0 deletions
diff --git a/public-inbox-httpd b/public-inbox-httpd
index 3635c9a7..0c1e24cb 100644
--- a/public-inbox-httpd
+++ b/public-inbox-httpd
@@ -53,11 +53,39 @@ daemon_run('0.0.0.0:8080', $refresh,
         });
 
 1;
+
+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->blocking(0);
+        $self->SUPER::new($io);
+        $self->{cb} = $cb;
+        $self->watch_read(1);
+        $self;
+}
+
+sub event_read { $_[0]->{cb}->() }
+sub event_hup { $_[0]->{cb}->() }
+sub sysread { shift->{sock}->sysread(@_) }
+
+1;
+
 package PublicInbox::HTTPD;
 use strict;
 use warnings;
 use Plack::Util;
 
+sub pi_httpd_async {
+        my ($io, $cb) = @_;
+        PublicInbox::HTTPD::Async->new($io, $cb);
+}
+
 sub new {
         my ($class, $sock, $app) = @_;
         my $n = getsockname($sock) or die "not a socket: $sock $!\n";
@@ -85,6 +113,10 @@ sub new {
                 'psgi.multiprocess' => Plack::Util::TRUE,
                 'psgix.harakiri'=> Plack::Util::FALSE,
                 'psgix.input.buffered' => Plack::Util::TRUE,
+                'pi-httpd.async' => do {
+                        no warnings 'once';
+                        *pi_httpd_async
+                },
         );
         bless {
                 err => \*STDERR,