]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Reorder the response reading in packet.pl to not fill TCP buffers
authorOndřej Surý <ondrej@isc.org>
Wed, 2 Sep 2020 10:44:36 +0000 (12:44 +0200)
committerOndřej Surý <ondrej@isc.org>
Wed, 2 Sep 2020 10:46:43 +0000 (12:46 +0200)
bin/tests/system/packet.pl

index 985b21c26f18150b47594549997efcebf1be5b12..f57cee928c75de4344e2ac2df10c2ac5f824cf2b 100644 (file)
@@ -90,51 +90,58 @@ print ("sending $repeats time(s): $output\n");
 my $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port,
                                 Proto => $proto,) or die "$!";
 
-my $bytes;
+STDOUT->autoflush(1);
+
+my $bytes = 0;
 while ($repeats > 0) {
     if ($proto eq "udp") {
-       $bytes = $sock->send($data);
+       $bytes += $sock->send($data);
     } else {
-       $bytes = $sock->syswrite(pack("n", $len), 2);
+       $bytes += $sock->syswrite(pack("n", $len), 2);
        $bytes += $sock->syswrite($data, $len);
     }
 
     $repeats = $repeats - 1;
-}
 
-print ("sent $bytes bytes to $addr:$port\n");
-if (defined $options{d}) {
-       use Net::DNS;
-       use Net::DNS::Packet;
-
-       my $rin;
-       my $rout;
-       $rin = '';
-        vec($rin, fileno($sock), 1) = 1;
-       select($rout = $rin, undef, undef, 1);
-       if (vec($rout, fileno($sock), 1)) {{
-                my $buf;
-               if ($proto eq "udp") {
-                       $sock->recv($buf, 512);
-               } else {
-                       my $n = $sock->sysread($buf, 2);
-                       last unless $n == 2;
-                       my $len = unpack("n", $buf);
-                       $n = $sock->sysread($buf, $len);
-                       last unless $n == $len;
-               }
-
-               my $response;
-               if ($Net::DNS::VERSION > 0.68) {
-                       $response = new Net::DNS::Packet(\$buf, 0);
-                       $@ and die $@;
-               } else {
-                       my $err;
-                       ($response, $err) = new Net::DNS::Packet(\$buf, 0);
-                       $err and die $err;
-               }
-               $response->print;
-       }}
+    if ($repeats % 100 == 0) {
+       print ".";
+    }
+
+    my $rin;
+    my $rout;
+    $rin = '';
+    vec($rin, fileno($sock), 1) = 1;
+    select($rout = $rin, undef, undef, 1);
+    if (vec($rout, fileno($sock), 1)) {
+       my $buf;
+
+       if ($proto eq "udp") {
+           $sock->recv($buf, 512);
+       } else {
+           my $n = $sock->sysread($buf, 2);
+           last unless $n == 2;
+           my $len = unpack("n", $buf);
+           $n = $sock->sysread($buf, $len);
+           last unless $n == $len;
+       }
+
+       if (defined $options{d}) {
+           use Net::DNS;
+           use Net::DNS::Packet;
+
+           my $response;
+           if ($Net::DNS::VERSION > 0.68) {
+               $response = new Net::DNS::Packet(\$buf, 0);
+               $@ and die $@;
+           } else {
+               my $err;
+               ($response, $err) = new Net::DNS::Packet(\$buf, 0);
+               $err and die $err;
+           }
+           $response->print;
+       }
+    }
 }
 $sock->close;
 close $file;
+print ("sent $bytes bytes to $addr:$port\n");