mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
ping: Fix broken count argument error
By storing count as an Optional<size_t>, we can leverage count's empty state to proceed with pinging indefinitely, and ensure a proper value is passed when count does have a value. This returns pings expected behavior to send infinite packets when a count is not specified, stop after sending a specified count, and disallow any count < 1. Closes #12524
This commit is contained in:
parent
24da85d059
commit
4cbce0e34c
1 changed files with 4 additions and 4 deletions
|
@ -26,7 +26,7 @@
|
|||
|
||||
static uint32_t total_pings;
|
||||
static int successful_pings;
|
||||
static uint32_t count;
|
||||
static Optional<size_t> count;
|
||||
static uint32_t total_ms;
|
||||
static int min_ms;
|
||||
static int max_ms;
|
||||
|
@ -67,8 +67,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
args_parser.add_option(payload_size, "Amount of bytes to send as payload in the ECHO_REQUEST packets.", "size", 's', "size");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
if (count < 1 || count > UINT32_MAX) {
|
||||
warnln("invalid count argument: '{}': out of range: 1 <= value <= {}", count, UINT32_MAX);
|
||||
if (count.has_value() && (count.value() < 1 || count.value() > UINT32_MAX)) {
|
||||
warnln("invalid count argument: '{}': out of range: 1 <= value <= {}", count.value(), UINT32_MAX);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
struct timeval tv_send;
|
||||
gettimeofday(&tv_send, nullptr);
|
||||
|
||||
if (count && total_pings == count)
|
||||
if (count.has_value() && total_pings == count.value())
|
||||
closing_statistics();
|
||||
else
|
||||
total_pings++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue