From: Ondřej Surý Date: Wed, 2 Sep 2020 10:44:36 +0000 (+0200) Subject: Reorder the response reading in packet.pl to not fill TCP buffers X-Git-Tag: v9.17.5~10^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ff133ebabd723847b0baaff6b1c852b20e7d62d4;p=thirdparty%2Fbind9.git Reorder the response reading in packet.pl to not fill TCP buffers --- diff --git a/bin/tests/system/packet.pl b/bin/tests/system/packet.pl index 985b21c26f1..f57cee928c7 100644 --- a/bin/tests/system/packet.pl +++ b/bin/tests/system/packet.pl @@ -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");