refactor(scheduler): split scheduler into 3 files
This commit is contained in:
parent
c859dc8ba8
commit
2d77cca584
4 changed files with 104 additions and 98 deletions
|
|
@ -36,7 +36,9 @@ PING_SRCS = $(CLI_SRCS) \
|
||||||
$(PING_SRC_DIR)/output/error.c \
|
$(PING_SRC_DIR)/output/error.c \
|
||||||
$(PING_SRC_DIR)/output/summary.c \
|
$(PING_SRC_DIR)/output/summary.c \
|
||||||
$(PING_SRC_DIR)/output/flood.c \
|
$(PING_SRC_DIR)/output/flood.c \
|
||||||
$(PING_SRC_DIR)/scheduler/scheduler.c \
|
$(PING_SRC_DIR)/scheduler/scheduler_arm.c \
|
||||||
|
$(PING_SRC_DIR)/scheduler/scheduler_select_tv.c \
|
||||||
|
$(PING_SRC_DIR)/scheduler/scheduler_init.c \
|
||||||
$(PING_SRC_DIR)/stats/stats_get.c \
|
$(PING_SRC_DIR)/stats/stats_get.c \
|
||||||
$(PING_SRC_DIR)/stats/stats_init.c \
|
$(PING_SRC_DIR)/stats/stats_init.c \
|
||||||
$(PING_SRC_DIR)/stats/stats_update.c \
|
$(PING_SRC_DIR)/stats/stats_update.c \
|
||||||
|
|
|
||||||
19
src/ping/scheduler/scheduler_arm.c
Normal file
19
src/ping/scheduler/scheduler_arm.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "ping/ft_ping_flags.h"
|
||||||
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
ping_scheduler_arm(const struct ping_config *config)
|
||||||
|
{
|
||||||
|
struct itimerval itv;
|
||||||
|
double interval;
|
||||||
|
|
||||||
|
if (HAS_FLAG(config->flags, FLAG_FLOOD))
|
||||||
|
return;
|
||||||
|
interval = (double)config->interval;
|
||||||
|
itv.it_value.tv_sec = (time_t)interval;
|
||||||
|
itv.it_value.tv_usec = (suseconds_t)((interval - (double)(time_t)interval)
|
||||||
|
* 1e6);
|
||||||
|
itv.it_interval.tv_sec = 0;
|
||||||
|
itv.it_interval.tv_usec = 0;
|
||||||
|
setitimer(ITIMER_REAL, &itv, NULL);
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#include "ping/ft_ping_flags.h"
|
|
||||||
#include "internal/ping/scheduler.h"
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static void sigalrm_handler(int sig);
|
static void inline sigint_handler(int sig);
|
||||||
static void sigint_handler(int sig);
|
static void inline sigalrm_handler(int sig);
|
||||||
static void install_signal(int signum, void (*handler)(int));
|
static void install_signal(int signum, void (*handler)(int));
|
||||||
/* -------------------- */
|
|
||||||
|
|
||||||
static struct ping_state *g_state = NULL;
|
static struct ping_state *g_state = NULL;
|
||||||
|
/* -------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
ping_scheduler_init(struct ping_state *state)
|
ping_scheduler_init(struct ping_state *state)
|
||||||
|
|
@ -18,44 +17,6 @@ ping_scheduler_init(struct ping_state *state)
|
||||||
install_signal(SIGINT, sigint_handler);
|
install_signal(SIGINT, sigint_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ping_scheduler_arm(const struct ping_config *config)
|
|
||||||
{
|
|
||||||
struct itimerval itv;
|
|
||||||
double interval;
|
|
||||||
|
|
||||||
if (HAS_FLAG(config->flags, FLAG_FLOOD))
|
|
||||||
return;
|
|
||||||
interval = (double)config->interval;
|
|
||||||
itv.it_value.tv_sec = (time_t)interval;
|
|
||||||
itv.it_value.tv_usec = (suseconds_t)((interval - (double)(time_t)interval)
|
|
||||||
* 1e6);
|
|
||||||
itv.it_interval.tv_sec = 0;
|
|
||||||
itv.it_interval.tv_usec = 0;
|
|
||||||
setitimer(ITIMER_REAL, &itv, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
|
||||||
{
|
|
||||||
tv->tv_usec = 0;
|
|
||||||
tv->tv_sec = (long)config->timeout * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sigalrm_handler(__unused int sig)
|
|
||||||
{
|
|
||||||
if (NULL != g_state)
|
|
||||||
g_state->send_flag = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
sigint_handler(__unused int sig)
|
|
||||||
{
|
|
||||||
if (NULL != g_state)
|
|
||||||
g_state->stop_flag = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
install_signal(int signum, void (*handler)(int))
|
install_signal(int signum, void (*handler)(int))
|
||||||
{
|
{
|
||||||
|
|
@ -66,3 +27,18 @@ install_signal(int signum, void (*handler)(int))
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
sigaction(signum, &sa, NULL);
|
sigaction(signum, &sa, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void inline
|
||||||
|
sigalrm_handler(__unused int sig)
|
||||||
|
{
|
||||||
|
if (NULL != g_state)
|
||||||
|
g_state->send_flag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void inline
|
||||||
|
sigint_handler(__unused int sig)
|
||||||
|
{
|
||||||
|
if (NULL != g_state)
|
||||||
|
g_state->stop_flag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
9
src/ping/scheduler/scheduler_select_tv.c
Normal file
9
src/ping/scheduler/scheduler_select_tv.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "ping/ft_ping_flags.h"
|
||||||
|
#include "internal/ping/scheduler.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
ping_scheduler_select_tv(const struct ping_config *config, struct timeval *tv)
|
||||||
|
{
|
||||||
|
tv->tv_usec = 0;
|
||||||
|
tv->tv_sec = (long)config->timeout * !HAS_FLAG(config->flags, FLAG_FLOOD);
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue