* [PATCH] http: avoid lseek if no input
@ 2016-04-29 20:21 7% Eric Wong
0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-04-29 20:21 UTC (permalink / raw)
To: meta
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(-)
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 973da34..414fc73 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) {
--
EW
^ permalink raw reply related [relevance 7%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-04-29 20:21 7% [PATCH] http: avoid lseek if no input Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).