about summary refs log tree commit homepage
path: root/lib/PublicInbox/HTTPD/Async.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-06-24 02:52:29 +0000
committerEric Wong <e@80x24.org>2019-06-24 05:26:26 +0000
commit8e1c3155da4edc082e8e3d8b30351f0c861757a7 (patch)
tree255a1c9ddb68b8c2ece212adc4ad1df677bec4c0 /lib/PublicInbox/HTTPD/Async.pm
parent2600289573c569fea65a1da817497414175bae55 (diff)
downloadpublic-inbox-8e1c3155da4edc082e8e3d8b30351f0c861757a7.tar.gz
We can reduce the amount of short-lived anonymous subs we
create by passing $self to code references.
Diffstat (limited to 'lib/PublicInbox/HTTPD/Async.pm')
-rw-r--r--lib/PublicInbox/HTTPD/Async.pm17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index e6df58eb..b46baeb2 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -34,23 +34,24 @@ sub new {
 
 sub restart_read ($) { $_[0]->watch(PublicInbox::DS::EPOLLIN()) }
 
-# fires after pending writes are complete:
-sub restart_read_cb ($) {
-        my ($self) = @_;
-        sub { restart_read($self) }
-}
-
 sub main_cb ($$$) {
         my ($http, $fh, $bref) = @_;
         sub {
                 my ($self) = @_;
                 my $r = sysread($self->{sock}, $$bref, 8192);
                 if ($r) {
-                        $fh->write($$bref);
+                        $fh->write($$bref); # may call $http->close
+
                         if ($http->{sock}) { # !closed
                                 if ($http->{wbuf}) {
+                                        # HTTP client could not keep up, so
+                                        # stop reading and buffering.
                                         $self->watch(0);
-                                        $http->write(restart_read_cb($self));
+
+                                        # Tell the HTTP socket to restart us
+                                        # when HTTP client is done draining
+                                        # $http->{wbuf}:
+                                        $http->enqueue_restart_pass;
                                 }
                                 # stay in EPOLLIN, but let other clients
                                 # get some work done, too.