about summary refs log tree commit homepage
path: root/lib/PublicInbox/DS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-06-24 02:52:13 +0000
committerEric Wong <e@80x24.org>2019-06-24 05:26:26 +0000
commite1b203f218b3fedea3068d6265130c47f0af9f4c (patch)
treef14166500298c29ab8e1e8bd06fc42af0beeb02a /lib/PublicInbox/DS.pm
parent676f13ac53bf96eab869514fe9fafcc0169874ab (diff)
downloadpublic-inbox-e1b203f218b3fedea3068d6265130c47f0af9f4c.tar.gz
No sense in having similar Linux-specific functionality in
both our NNTP.pm and HTTP.pm
Diffstat (limited to 'lib/PublicInbox/DS.pm')
-rw-r--r--lib/PublicInbox/DS.pm21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index ba8bd95f..3e8b0b1a 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -21,7 +21,7 @@ use IO::Handle qw();
 use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
 use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
 use parent qw(Exporter);
-our @EXPORT_OK = qw(now);
+our @EXPORT_OK = qw(now msg_more);
 use warnings;
 
 use PublicInbox::Syscall qw(:epoll);
@@ -561,6 +561,25 @@ sub write {
     }
 }
 
+use constant MSG_MORE => ($^O eq 'linux') ? 0x8000 : 0;
+
+sub msg_more ($$) {
+    my $self = $_[0];
+    my $sock = $self->{sock} or return 1;
+
+    if (MSG_MORE && !$self->{wbuf}) {
+        my $n = send($sock, $_[1], MSG_MORE);
+        if (defined $n) {
+            my $nlen = bytes::length($_[1]) - $n;
+            return 1 if $nlen == 0; # all done!
+
+            # PublicInbox::DS::write queues the unwritten substring:
+            return $self->write(substr($_[1], $n, $nlen));
+        }
+    }
+    $self->write(\($_[1]));
+}
+
 =head2 C<< $obj->watch_read( $boolean ) >>
 
 Turn 'readable' event notification on or off.