user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] switch to sysseek + sysread for serving static files
@ 2020-01-25 20:57 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-01-25 20:57 UTC (permalink / raw)
  To: meta

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;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-25 20:57 [PATCH] switch to sysseek + sysread for serving static files Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git