]> Sergey Matveev's repositories - public-inbox.git/commitdiff
http: avoid lseek if no input
authorEric Wong <e@80x24.org>
Fri, 29 Apr 2016 20:21:39 +0000 (20:21 +0000)
committerEric Wong <e@80x24.org>
Fri, 29 Apr 2016 20:22:10 +0000 (20:22 +0000)
This saves us a system call for common GET/HEAD requests
with no upload body.

lib/PublicInbox/HTTP.pm

index 973da3418c76282e3d38989c0e04f1130c4349f1..414fc733a99be34d483f4126e2f8361d0e15f0ca 100644 (file)
@@ -118,11 +118,11 @@ sub event_read_input ($) {
                return recv_err($self, $r, $len) unless $r;
                # continue looping if $r > 0;
        }
-       app_dispatch($self);
+       app_dispatch($self, $input);
 }
 
-sub app_dispatch ($) {
-       my ($self) = @_;
+sub app_dispatch {
+       my ($self, $input) = @_;
        $self->watch_read(0);
        my $env = $self->{env};
        $env->{REMOTE_ADDR} = $self->{remote_addr};
@@ -131,10 +131,10 @@ sub app_dispatch ($) {
                $host =~ s/:(\d+)\z// and $env->{SERVER_PORT} = $1;
                $env->{SERVER_NAME} = $host;
        }
-
-       sysseek($env->{'psgi.input'}, 0, SEEK_SET) or
+       if (defined $input) {
+               sysseek($input, 0, SEEK_SET) or
                        die "BUG: psgi.input seek failed: $!";
-
+       }
        # note: NOT $self->{sock}, we want our close (+ Danga::Socket::close),
        # to do proper cleanup:
        $env->{'psgix.io'} = $self; # only for ->close
@@ -306,7 +306,8 @@ sub event_read_input_chunked { # unlikely...
 
        while (1) { # chunk start
                if ($len == CHUNK_ZEND) {
-                       return app_dispatch($self) if $$rbuf =~ s/\A\r\n//s;
+                       $$rbuf =~ s/\A\r\n//s and
+                               return app_dispatch($self, $input);
                        return quit($self, 400) if length($$rbuf) > 2;
                }
                if ($len == CHUNK_END) {