about summary refs log tree commit homepage
path: root/lib/PublicInbox/HTTPD/Async.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-01-08 04:25:51 +0000
committerEric Wong <e@80x24.org>2017-01-08 04:25:51 +0000
commit98a24a7404181006b2a102e9ae5e3a8938fdc172 (patch)
tree287458df7979453cef60dfbdfbc094794300c09a /lib/PublicInbox/HTTPD/Async.pm
parent68f83ca5236078128a0ccf47a1e54bd955777120 (diff)
parentf1a38b18d9a46531e18143a7cd4c7a66fc89adbc (diff)
downloadpublic-inbox-98a24a7404181006b2a102e9ae5e3a8938fdc172.tar.gz
* origin/master:
  inbox: properly register cleanup timer for git processes
  search: remove subject_summary
  searchmsg: favor direct hash access over accessor methods
  remove incorrect comment about strftime + locales
  config: allow per-inbox nntpserver
  inbox: eliminate weaken usage entirely
  inbox: describe the full key name
  config: remove unused get() method
  config: always use namespaced "publicinboxlimiter"
  qspawn: prepare to support runtime reloading of Limiter
  http: remove weaken usage, reduce anonsub capture scope
  httpd/async: remove weaken usage
  http: fix spelling error
  watch: watchspam affects all configured inboxes
  doc: minor updates to design notes
Diffstat (limited to 'lib/PublicInbox/HTTPD/Async.pm')
-rw-r--r--lib/PublicInbox/HTTPD/Async.pm31
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index 79951ca6..54b62451 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -10,7 +10,6 @@ use strict;
 use warnings;
 use base qw(Danga::Socket);
 use fields qw(cb cleanup);
-use Scalar::Util qw(weaken);
 require PublicInbox::EvCleanup;
 
 sub new {
@@ -29,22 +28,17 @@ sub restart_read_cb ($) {
         sub { $self->watch_read(1) }
 }
 
-sub async_pass {
-        my ($self, $http, $fh, $bref) = @_;
-        # In case the client HTTP connection ($http) dies, it
-        # will automatically close this ($self) object.
-        $http->{forward} = $self;
-        $fh->write($$bref);
-        my $restart_read = restart_read_cb($self);
-        weaken($self);
-        $self->{cb} = sub {
+sub main_cb ($$$) {
+        my ($http, $fh, $bref) = @_;
+        sub {
+                my ($self) = @_;
                 my $r = sysread($self->{sock}, $$bref, 8192);
                 if ($r) {
                         $fh->write($$bref);
                         return if $http->{closed};
                         if ($http->{write_buf_size}) {
                                 $self->watch_read(0);
-                                $http->write($restart_read); # D::S::write
+                                $http->write(restart_read_cb($self));
                         }
                         # stay in watch_read, but let other clients
                         # get some work done, too.
@@ -60,9 +54,18 @@ sub async_pass {
         }
 }
 
-sub event_read { $_[0]->{cb}->() }
-sub event_hup { $_[0]->{cb}->() }
-sub event_err { $_[0]->{cb}->() }
+sub async_pass {
+        my ($self, $http, $fh, $bref) = @_;
+        # In case the client HTTP connection ($http) dies, it
+        # will automatically close this ($self) object.
+        $http->{forward} = $self;
+        $fh->write($$bref); # PublicInbox:HTTP::{chunked,identity}_wcb
+        $self->{cb} = main_cb($http, $fh, $bref);
+}
+
+sub event_read { $_[0]->{cb}->(@_) }
+sub event_hup { $_[0]->{cb}->(@_) }
+sub event_err { $_[0]->{cb}->(@_) }
 sub sysread { shift->{sock}->sysread(@_) }
 
 sub close {