fix: rename timeout/deadline to linger/timeout
This commit is contained in:
parent
606069df82
commit
7a76ff8d2a
11 changed files with 34 additions and 21 deletions
|
|
@ -79,17 +79,17 @@ enum {
|
||||||
) \
|
) \
|
||||||
X( \
|
X( \
|
||||||
'W', \
|
'W', \
|
||||||
"timeout", \
|
"linger", \
|
||||||
required_argument, \
|
required_argument, \
|
||||||
cli_handle_timeout, \
|
cli_handle_linger, \
|
||||||
OPT_ARG_SECONDS, \
|
OPT_ARG_SECONDS, \
|
||||||
"Timeout for replies in seconds" \
|
"Timeout for replies in seconds" \
|
||||||
) \
|
) \
|
||||||
X( \
|
X( \
|
||||||
'w', \
|
'w', \
|
||||||
"deadline", \
|
"timeout", \
|
||||||
required_argument, \
|
required_argument, \
|
||||||
cli_handle_deadline, \
|
cli_handle_timeout, \
|
||||||
OPT_ARG_SECONDS, \
|
OPT_ARG_SECONDS, \
|
||||||
"Exit after N seconds regardless of packets sent/received" \
|
"Exit after N seconds regardless of packets sent/received" \
|
||||||
) \
|
) \
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ int cli_handle_count(const char *arg, void *config);
|
||||||
int cli_handle_preload(const char *arg, void *config);
|
int cli_handle_preload(const char *arg, void *config);
|
||||||
int cli_handle_pattern(const char *arg, void *config);
|
int cli_handle_pattern(const char *arg, void *config);
|
||||||
int cli_handle_dont_fragment(const char *arg, void *config);
|
int cli_handle_dont_fragment(const char *arg, void *config);
|
||||||
int cli_handle_deadline(const char *arg, void *config);
|
|
||||||
int cli_handle_flood(const char *arg, void *config);
|
int cli_handle_flood(const char *arg, void *config);
|
||||||
int cli_handle_help(const char *arg, void *config);
|
int cli_handle_help(const char *arg, void *config);
|
||||||
int cli_handle_interval(const char *arg, void *config);
|
int cli_handle_interval(const char *arg, void *config);
|
||||||
int cli_handle_quiet(const char *arg, void *config);
|
int cli_handle_quiet(const char *arg, void *config);
|
||||||
int cli_handle_size(const char *arg, void *config);
|
int cli_handle_size(const char *arg, void *config);
|
||||||
|
int cli_handle_linger(const char *arg, void *config);
|
||||||
int cli_handle_timeout(const char *arg, void *config);
|
int cli_handle_timeout(const char *arg, void *config);
|
||||||
int cli_handle_ttl(const char *arg, void *config);
|
int cli_handle_ttl(const char *arg, void *config);
|
||||||
int cli_handle_verbose(const char *arg, void *config);
|
int cli_handle_verbose(const char *arg, void *config);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#define DEFAULT_INTERVAL 1.0
|
#define DEFAULT_INTERVAL 1.0
|
||||||
#define DEFAULT_TTL 64
|
#define DEFAULT_TTL 64
|
||||||
#define DEFAULT_PACKET_SIZE 56
|
#define DEFAULT_PACKET_SIZE 56
|
||||||
#define DEFAULT_TIMEOUT 1.0
|
#define DEFAULT_LINGER 1.0
|
||||||
|
|
||||||
/* Maximum values */
|
/* Maximum values */
|
||||||
#define MAX_PACKET_SIZE 65507
|
#define MAX_PACKET_SIZE 65507
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ struct ping_config
|
||||||
double interval;
|
double interval;
|
||||||
uint8_t ttl;
|
uint8_t ttl;
|
||||||
size_t packet_size;
|
size_t packet_size;
|
||||||
|
double linger;
|
||||||
double timeout;
|
double timeout;
|
||||||
double deadline;
|
|
||||||
|
|
||||||
/* Pattern (-p) */
|
/* Pattern (-p) */
|
||||||
uint8_t pattern[16];
|
uint8_t pattern[16];
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ libping_core_la_SOURCES = \
|
||||||
cli/handlers/handle_preload.c \
|
cli/handlers/handle_preload.c \
|
||||||
cli/handlers/handle_pattern.c \
|
cli/handlers/handle_pattern.c \
|
||||||
cli/handlers/handle_dont_fragment.c \
|
cli/handlers/handle_dont_fragment.c \
|
||||||
cli/handlers/handle_deadline.c \
|
cli/handlers/handle_linger.c \
|
||||||
cli/handlers/handle_flood.c \
|
cli/handlers/handle_flood.c \
|
||||||
cli/handlers/handle_help.c \
|
cli/handlers/handle_help.c \
|
||||||
cli/handlers/handle_interval.c \
|
cli/handlers/handle_interval.c \
|
||||||
|
|
|
||||||
14
src/ping/cli/handlers/handle_linger.c
Normal file
14
src/ping/cli/handlers/handle_linger.c
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "ping/cli.h"
|
||||||
|
#include "internal/cli/parse_utils.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
cli_handle_linger(const char *arg, void *config_void)
|
||||||
|
{
|
||||||
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
|
float linger;
|
||||||
|
|
||||||
|
if (0 != cli_parse_ufloat(arg, &linger))
|
||||||
|
return CLI_ERROR;
|
||||||
|
config->linger = linger;
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -5,11 +5,10 @@ int
|
||||||
cli_handle_timeout(const char *arg, void *config_void)
|
cli_handle_timeout(const char *arg, void *config_void)
|
||||||
{
|
{
|
||||||
struct ping_config *config = (struct ping_config *)config_void;
|
struct ping_config *config = (struct ping_config *)config_void;
|
||||||
float TO;
|
float timeout;
|
||||||
|
|
||||||
if (0 != cli_parse_ufloat(arg, &TO))
|
if (0 != cli_parse_ufloat(arg, &timeout))
|
||||||
return CLI_ERROR;
|
return CLI_ERROR;
|
||||||
|
config->timeout = timeout;
|
||||||
config->timeout = TO;
|
|
||||||
return CLI_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ print_help(void)
|
||||||
const struct option_descriptor *opt = &g_options[i];
|
const struct option_descriptor *opt = &g_options[i];
|
||||||
const char *argstr = option_arg_type_to_str(opt->arg_type);
|
const char *argstr = option_arg_type_to_str(opt->arg_type);
|
||||||
|
|
||||||
printf(" -%c, --%-10s %-8s %s\n",
|
printf(" -%c, --%-15s %-8s %s\n",
|
||||||
opt->short_opt,
|
opt->short_opt,
|
||||||
opt->long_opt,
|
opt->long_opt,
|
||||||
argstr[0] ? argstr : "",
|
argstr[0] ? argstr : "",
|
||||||
|
|
|
||||||
|
|
@ -35,5 +35,5 @@ init_config(struct ping_config *config)
|
||||||
config->interval = DEFAULT_INTERVAL;
|
config->interval = DEFAULT_INTERVAL;
|
||||||
config->ttl = DEFAULT_TTL;
|
config->ttl = DEFAULT_TTL;
|
||||||
config->packet_size = DEFAULT_PACKET_SIZE;
|
config->packet_size = DEFAULT_PACKET_SIZE;
|
||||||
config->timeout = DEFAULT_TIMEOUT;
|
config->linger = DEFAULT_LINGER;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include "internal/ping/scheduler.h"
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int deadline_expired(const struct ping_state *state);
|
static int timeout_expired(const struct ping_state *state);
|
||||||
static int linger_expired(const struct ping_state *state);
|
static int linger_expired(const struct ping_state *state);
|
||||||
static int should_stop(const struct ping_state *state);
|
static int should_stop(const struct ping_state *state);
|
||||||
static int can_send_more(const struct ping_state *state);
|
static int can_send_more(const struct ping_state *state);
|
||||||
|
|
@ -28,18 +28,18 @@ ping_loop(struct ping_state *state, size_t payload_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
deadline_expired(const struct ping_state *state)
|
timeout_expired(const struct ping_state *state)
|
||||||
{
|
{
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
double elapsed;
|
double elapsed;
|
||||||
|
|
||||||
if (0.0 == state->config->deadline)
|
if (0.0 == state->config->timeout)
|
||||||
return 0;
|
return 0;
|
||||||
if (0 != icmp_get_time(&now))
|
if (0 != icmp_get_time(&now))
|
||||||
return 0;
|
return 0;
|
||||||
elapsed = (double)(now.tv_sec - state->start_time.tv_sec)
|
elapsed = (double)(now.tv_sec - state->start_time.tv_sec)
|
||||||
+ (double)(now.tv_nsec - state->start_time.tv_nsec) / 1e9;
|
+ (double)(now.tv_nsec - state->start_time.tv_nsec) / 1e9;
|
||||||
return elapsed >= state->config->deadline;
|
return elapsed >= state->config->timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -54,7 +54,7 @@ linger_expired(const struct ping_state *state)
|
||||||
return 0;
|
return 0;
|
||||||
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
elapsed = (double)(now.tv_sec - state->linger_start.tv_sec)
|
||||||
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
+ (double)(now.tv_nsec - state->linger_start.tv_nsec) / 1e9;
|
||||||
return elapsed >= state->config->timeout;
|
return elapsed >= state->config->linger;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -64,7 +64,7 @@ should_stop(const struct ping_state *state)
|
||||||
|
|
||||||
if (state->stop_flag)
|
if (state->stop_flag)
|
||||||
return 1;
|
return 1;
|
||||||
if (deadline_expired(state))
|
if (timeout_expired(state))
|
||||||
return 1;
|
return 1;
|
||||||
if (linger_expired(state))
|
if (linger_expired(state))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,5 @@ void
|
||||||
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
||||||
{
|
{
|
||||||
tv->tv_usec = 0;
|
tv->tv_usec = 0;
|
||||||
tv->tv_sec = (long)config->timeout * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
tv->tv_sec = (long)config->linger * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue