From 1acd8fdc49c270335257251ea3f1fd3798f09b8f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 29 Apr 2016 20:21:39 +0000 Subject: http: avoid lseek if no input This saves us a system call for common GET/HEAD requests with no upload body. --- lib/PublicInbox/HTTP.pm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 973da341..414fc733 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -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) { -- cgit v1.2.3-24-ge0c7