From 2929e3b3c62925149a9a8cafd872bfdb017453eb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Jun 2019 02:52:14 +0000 Subject: ds: switch write buffering to use a tempfile Data which can't fit into a generously-sized socket buffer, has no business being stored in heap. --- lib/PublicInbox/HTTP.pm | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'lib/PublicInbox/HTTP.pm') diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index a669eb6e..fcb5eb6c 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -19,7 +19,7 @@ use HTTP::Status qw(status_message); use HTTP::Date qw(time2str); use IO::Handle; require PublicInbox::EvCleanup; -PublicInbox::DS->import('msg_more'); +PublicInbox::DS->import(qw(msg_more write_in_full)); use constant { CHUNK_START => -1, # [a-f0-9]+\r\n CHUNK_END => -2, # \r\n @@ -125,7 +125,7 @@ sub read_input ($) { while ($len > 0) { if ($$rbuf ne '') { - my $w = write_in_full($input, $rbuf, $len); + my $w = write_in_full($input, $rbuf, $len, 0); return write_err($self, $len) unless $w; $len -= $w; die "BUG: $len < 0 (w=$w)" if $len < 0; @@ -367,20 +367,6 @@ sub recv_err { quit($self, 500); } -sub write_in_full { - my ($fh, $rbuf, $len) = @_; - my $rv = 0; - my $off = 0; - while ($len > 0) { - my $w = syswrite($fh, $$rbuf, $len, $off); - return ($rv ? $rv : $w) unless $w; # undef or 0 - $rv += $w; - $off += $w; - $len -= $w; - } - $rv -} - sub read_input_chunked { # unlikely... my ($self) = @_; my $input = $self->{env}->{'psgi.input'}; @@ -425,7 +411,7 @@ sub read_input_chunked { # unlikely... # drain the current chunk until ($len <= 0) { if ($$rbuf ne '') { - my $w = write_in_full($input, $rbuf, $len); + my $w = write_in_full($input, $rbuf, $len, 0); return write_err($self, "$len chunk") if !$w; $len -= $w; if ($len == 0) { -- cgit v1.2.3-24-ge0c7