From e74324ad34c3522a8af141b9d094043a29b9a0fc Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 26 May 2023 06:14:22 +0100 Subject: [PATCH] ping: Don't wait before displaying closing statistics Previously, we would wait for the ping interval after the last ping before displaying the closing statistics. We now display the closing statistics and exit as soon as the required number of pings has been performed. --- Userland/Utilities/ping.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Userland/Utilities/ping.cpp b/Userland/Utilities/ping.cpp index f543094e0c..83b703e3bf 100644 --- a/Userland/Utilities/ping.cpp +++ b/Userland/Utilities/ping.cpp @@ -159,11 +159,6 @@ ErrorOr serenity_main(Main::Arguments arguments) struct timeval tv_send; gettimeofday(&tv_send, nullptr); - if (count.has_value() && total_pings == count.value()) - closing_statistics(); - else - total_pings++; - TRY(Core::System::sendto(fd, ping_packet.data(), ping_packet.size(), 0, (const struct sockaddr*)&peer_address, sizeof(sockaddr_in))); for (;;) { @@ -239,6 +234,10 @@ ErrorOr serenity_main(Main::Arguments arguments) break; } + total_pings++; + if (count.has_value() && total_pings == count.value()) + closing_statistics(); + clock_nanosleep(CLOCK_MONOTONIC, 0, &interval_timespec, nullptr); } }