]> Sergey Matveev's repositories - public-inbox.git/blobdiff - public-inbox-httpd
httpd: fill in missing Danga::Socket callbacks
[public-inbox.git] / public-inbox-httpd
index 6436bd7df1011cbfbff3e26bb6197d59d54852d7..772333e8b0a49a084f14853c6ae9c5a27796473f 100644 (file)
@@ -24,6 +24,7 @@ my $refresh = sub {
 "$0 runs in /, command-line paths must be absolute\n";
                }
        } else {
+               my $www = PublicInbox::WWW->new;
                $app = eval {
                        my $deflate_types = eval {
                                require Plack::Middleware::Deflater;
@@ -37,11 +38,7 @@ my $refresh = sub {
                                                content_type => $deflate_types
                                }
                                enable 'Head';
-                               sub {
-                                       my $req = Plack::Request->new(@_);
-                                       PublicInbox::WWW::run($req,
-                                                       $req->method);
-                               };
+                               sub { $www->call(@_) };
                        };
                };
        }
@@ -56,11 +53,40 @@ 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 event_err { $_[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";
@@ -88,6 +114,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,