]> Sergey Matveev's repositories - public-inbox.git/commitdiff
ds: use MSG_MORE when wbuf is empty during long responses
authorEric Wong <e@80x24.org>
Sat, 28 Dec 2019 20:55:16 +0000 (20:55 +0000)
committerEric Wong <e@80x24.org>
Sat, 28 Dec 2019 21:42:51 +0000 (21:42 +0000)
HTTP::getline_pull and NNTP::long_step will both populate {wbuf}
manually to avoid recursion, so we need to account for an
empty-but-present {wbuf} while dispatching msg_more().

lib/PublicInbox/DS.pm

index 62aa3c2d94aa6bff6f4007937b52b45fbd1c64de..8f17f7fb3d3b0db79ae5ebc93ba6aa9fb0e2daa5 100644 (file)
@@ -574,15 +574,18 @@ use constant MSG_MORE => ($^O eq 'linux') ? 0x8000 : 0;
 sub msg_more ($$) {
     my $self = $_[0];
     my $sock = $self->{sock} or return 1;
+    my $wbuf = $self->{wbuf};
 
-    if (MSG_MORE && !$self->{wbuf} && ref($sock) ne 'IO::Socket::SSL') {
+    if (MSG_MORE && (!defined($wbuf) || !scalar(@$wbuf)) &&
+               ref($sock) ne 'IO::Socket::SSL') {
         my $n = send($sock, $_[1], MSG_MORE);
         if (defined $n) {
             my $nlen = bytes::length($_[1]) - $n;
             return 1 if $nlen == 0; # all done!
             # queue up the unwritten substring:
             my $tmpio = tmpio($self, \($_[1]), $n) or return 0;
-            $self->{wbuf} = [ $tmpio ];
+            $self->{wbuf} //= $wbuf //= [];
+            push @$wbuf, $tmpio;
             epwait($sock, EPOLLOUT|EPOLLONESHOT);
             return 0;
         }