user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH] switch to sysseek + sysread for serving static files
Date: Sat, 25 Jan 2020 20:57:57 +0000	[thread overview]
Message-ID: <20200125205757.65532-1-e@yhbt.net> (raw)

The "perlio" layer doesn't do read(2) syscalls over 8192 bytes
at the moment, and binmode($fh, ':unix') leaks[1].  So use
sysseek and sysread for now, since I can't see retaining
compatibility with PerlIO::scalar being worth the trouble.

[1] http://nntp.perl.org/group/perl.perl5.porters/256918
---
 lib/PublicInbox/DS.pm        | 4 ++--
 lib/PublicInbox/WwwStatic.pm | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index c76a5038..4d685131 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -395,10 +395,10 @@ sub close {
 sub send_tmpio ($$) {
     my ($sock, $tmpio) = @_;
 
-    seek($tmpio->[0], $tmpio->[1], SEEK_SET) or return;
+    sysseek($tmpio->[0], $tmpio->[1], SEEK_SET) or return;
     my $n = $tmpio->[2] // 65536;
     $n = 65536 if $n > 65536;
-    defined(my $to_write = read($tmpio->[0], my $buf, $n)) or return;
+    defined(my $to_write = sysread($tmpio->[0], my $buf, $n)) or return;
     my $written = 0;
     while ($to_write > 0) {
         if (defined(my $w = syswrite($sock, $buf, $to_write, $written))) {
diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm
index 60a71d8d..547b75bb 100644
--- a/lib/PublicInbox/WwwStatic.pm
+++ b/lib/PublicInbox/WwwStatic.pm
@@ -176,9 +176,9 @@ sub getline {
 	my $len = $self->{len} or return; # undef, tells server we're done
 	my $n = 8192;
 	$n = $len if $len < $n;
-	seek($self->{in}, $self->{off}, SEEK_SET) or
-			die "seek ($self->{path}): $!";
-	my $r = read($self->{in}, my $buf, $n);
+	sysseek($self->{in}, $self->{off}, SEEK_SET) or
+			die "sysseek ($self->{path}): $!";
+	my $r = sysread($self->{in}, my $buf, $n);
 	if (defined $r && $r > 0) { # success!
 		$self->{len} = $len - $r;
 		$self->{off} += $r;

                 reply	other threads:[~2020-01-25 20:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200125205757.65532-1-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).