about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-09 10:09:42 +0000
committerEric Wong <e@80x24.org>2023-11-09 21:53:52 +0000
commitb35530ccb929a693c4c78b02187a564a7ab5e903 (patch)
treec5c51d18ff0ab90edaab25a8a2e2c6de864a8d84 /lib/PublicInbox
parent2998570b415c44815b2301ba13d63a4746226f0f (diff)
downloadpublic-inbox-b35530ccb929a693c4c78b02187a564a7ab5e903.tar.gz
In the rare case sendmsg(2) isn't able to send the full amount
(due to buffers >=2GB on Linux), use print + (autodie)close
to send the remainder and retry on EINTR.  `substr' should be
able to avoid a large malloc via offsets and CoW on modern Perl.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/IPC.pm13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/PublicInbox/IPC.pm b/lib/PublicInbox/IPC.pm
index 3292d960..a5cae6f2 100644
--- a/lib/PublicInbox/IPC.pm
+++ b/lib/PublicInbox/IPC.pm
@@ -10,7 +10,7 @@
 package PublicInbox::IPC;
 use v5.12;
 use parent qw(Exporter);
-use autodie qw(fork pipe read socketpair sysread);
+use autodie qw(close fork pipe read socketpair sysread);
 use Carp qw(croak);
 use PublicInbox::DS qw(awaitpid);
 use PublicInbox::Spawn;
@@ -266,15 +266,8 @@ sub stream_in_full ($$$) {
                         0) // croak "sendmsg: $!";
         undef $r;
         $n = $send_cmd->($w, $fds, $buf, 0) // croak "sendmsg: $!";
-        while ($n < length($buf)) {
-                my $x = syswrite($w, $buf, length($buf) - $n, $n);
-                if (!defined($n)) {
-                        next if $!{EINTR};
-                        croak "syswrite: $!";
-                }
-                $x or croak "syswrite wrote 0 bytes";
-                $n += $x;
-        }
+        print $w substr($buf, $n) if $n < length($buf); # need > 2G on Linux
+        close $w; # autodies
 }
 
 sub wq_io_do { # always async