From 28eab34ecea8b3677808c00cebbf4bd3227f8c68 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Mon, 22 Jun 2020 12:07:48 +0200 Subject: Use more descriptive names in struct cfg --- announce.c | 58 +++++++++++++++++++++++++++++----------------------------- main.c | 40 ++++++++++++++++++++-------------------- main.h | 6 +++--- uring.c | 50 ++++++++++++++++++++++++++------------------------ 4 files changed, 78 insertions(+), 76 deletions(-) diff --git a/announce.c b/announce.c index 1225868..17ab2bb 100644 --- a/announce.c +++ b/announce.c @@ -20,51 +20,51 @@ struct announce { static void announce_cb(struct uring_task *task, int res) { - struct announce *aev = container_of(task, struct announce, task); + struct announce *announce = container_of(task, struct announce, task); struct server *server; assert_return(task); assert_task_alive(DBG_ANN, task); - if (res != sizeof(aev->value)) { + if (res != sizeof(announce->value)) { error("timerfd_read: %m"); return; } - debug(DBG_ANN, "timerfd value %" PRIu64, aev->value); + debug(DBG_ANN, "timerfd value %" PRIu64, announce->value); list_for_each_entry(server, &cfg->servers, list) - server_announce(server, aev->mcast_fd); - uring_read(&aev->task, &aev->value, sizeof(aev->value), announce_cb); + server_announce(server, announce->mcast_fd); + uring_read(&announce->task, &announce->value, sizeof(announce->value), announce_cb); } static void announce_free(struct uring_task *task) { - struct announce *aev = container_of(task, struct announce, task); + struct announce *announce = container_of(task, struct announce, task); assert_return(task); - debug(DBG_ANN, "task %p, aev 0x%p, mcast_fd: %i", - task, aev, aev->mcast_fd); - close(aev->mcast_fd); - xfree(aev); + debug(DBG_ANN, "task %p, announce 0x%p, mcast_fd: %i", + task, announce, announce->mcast_fd); + close(announce->mcast_fd); + xfree(announce); } void announce_refdump() { - assert_return_silent(cfg->aev); + assert_return_silent(cfg->announce); - uring_task_refdump(&cfg->aev->task); + uring_task_refdump(&cfg->announce->task); } void announce_delete() { - assert_return(cfg->aev); + assert_return(cfg->announce); - debug(DBG_ANN, "closing fd %i", cfg->aev->task.fd); - uring_task_destroy(&cfg->aev->task); - cfg->aev = NULL; + debug(DBG_ANN, "closing fd %i", cfg->announce->task.fd); + uring_task_destroy(&cfg->announce->task); + cfg->announce = NULL; } void @@ -81,9 +81,9 @@ announce_stop() } }; - assert_return(cfg->aev); + assert_return(cfg->announce); - if (timerfd_settime(cfg->aev->task.fd, 0, &tspec, NULL) != 0) + if (timerfd_settime(cfg->announce->task.fd, 0, &tspec, NULL) != 0) error("timerfd_settime: %m"); } @@ -101,23 +101,23 @@ announce_start() } }; - assert_return(cfg->aev); + assert_return(cfg->announce); - if (timerfd_settime(cfg->aev->task.fd, 0, &tspec, NULL) != 0) + if (timerfd_settime(cfg->announce->task.fd, 0, &tspec, NULL) != 0) error("timerfd_settime: %m"); } void announce_init() { - struct announce *aev; + struct announce *announce; int afd; int sfd; - assert_return(!cfg->aev); + assert_return(!cfg->announce); - aev = zmalloc(sizeof(*aev)); - if (!aev) + announce = zmalloc(sizeof(*announce)); + if (!announce) die("malloc: %m"); afd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); @@ -128,10 +128,10 @@ announce_init() if (sfd < 0) die("socket: %m"); - uring_task_init(&aev->task, "announce", uring_parent(), announce_free); - uring_task_set_fd(&aev->task, afd); - aev->mcast_fd = sfd; - cfg->aev = aev; - uring_read(&aev->task, &aev->value, sizeof(aev->value), announce_cb); + uring_task_init(&announce->task, "announce", uring_parent(), announce_free); + uring_task_set_fd(&announce->task, afd); + announce->mcast_fd = sfd; + cfg->announce = announce; + uring_read(&announce->task, &announce->value, sizeof(announce->value), announce_cb); } diff --git a/main.c b/main.c index c240da2..1dbc3c2 100644 --- a/main.c +++ b/main.c @@ -546,14 +546,14 @@ struct signalfd_ev { static void signalfd_free(struct uring_task *task) { - struct signalfd_ev *sev = container_of(task, struct signalfd_ev, task); + struct signalfd_ev *signal = container_of(task, struct signalfd_ev, task); assert_return(task); debug(DBG_SIG, "called"); - close(sev->pipe[PIPE_WR]); - cfg->sev = NULL; - xfree(sev); + close(signal->pipe[PIPE_WR]); + cfg->signal = NULL; + xfree(signal); } static void @@ -568,8 +568,8 @@ dump_tree() info("Dumping Tree"); info("============"); uring_task_refdump(&cfg->task); - if (cfg->sev) - uring_task_refdump(&cfg->sev->task); + if (cfg->signal) + uring_task_refdump(&cfg->signal->task); uring_refdump(); idle_refdump(); igmp_refdump(); @@ -584,7 +584,7 @@ dump_tree() static void signalfd_read(struct uring_task *task, int res) { - struct signalfd_ev *sev = container_of(task, struct signalfd_ev, task); + struct signalfd_ev *signal = container_of(task, struct signalfd_ev, task); struct server *server, *stmp; static unsigned count = 0; siginfo_t *si; @@ -641,7 +641,7 @@ signalfd_read(struct uring_task *task, int res) verbose("got a signal to dump tree"); sd_notifyf(0, "STOPPING=1\nSTATUS=Received signal, exiting"); dump_tree(); - uring_task_destroy(&sev->task); + uring_task_destroy(&signal->task); igmp_delete(); announce_delete(); idle_delete(); @@ -657,7 +657,7 @@ signalfd_read(struct uring_task *task, int res) } out: - uring_tbuf_read(&sev->task, signalfd_read); + uring_tbuf_read(&signal->task, signalfd_read); } static void @@ -667,7 +667,7 @@ hack_signal_handler(int signum, siginfo_t *si, void *ucontext) assert_return(signum > 0 && si); - r = write(cfg->sev->pipe[PIPE_WR], si, sizeof(*si)); + r = write(cfg->signal->pipe[PIPE_WR], si, sizeof(*si)); if (r != sizeof(*si)) error("write: %zi\n", r); @@ -677,13 +677,13 @@ static void signalfd_init() { //sigset_t mask; - struct signalfd_ev *sev; + struct signalfd_ev *signal; - sev = zmalloc(sizeof(*sev)); - if (!sev) + signal = zmalloc(sizeof(*signal)); + if (!signal) die("malloc: %m"); - if (pipe2(sev->pipe, O_CLOEXEC) < 0) + if (pipe2(signal->pipe, O_CLOEXEC) < 0) die("pipe2: %m"); /* @@ -712,12 +712,12 @@ signalfd_init() sigaction(SIGPIPE, &action, NULL); debug(DBG_SIG, "using pipe fds %i -> %i", - sev->pipe[PIPE_WR], sev->pipe[PIPE_RD]); - uring_task_init(&sev->task, "signal", uring_parent(), signalfd_free); - uring_task_set_fd(&sev->task, sev->pipe[PIPE_RD]); - uring_task_set_buf(&sev->task, &sev->tbuf); - cfg->sev = sev; - uring_tbuf_read(&sev->task, signalfd_read); + signal->pipe[PIPE_WR], signal->pipe[PIPE_RD]); + uring_task_init(&signal->task, "signal", uring_parent(), signalfd_free); + uring_task_set_fd(&signal->task, signal->pipe[PIPE_RD]); + uring_task_set_buf(&signal->task, &signal->tbuf); + cfg->signal = signal; + uring_tbuf_read(&signal->task, signalfd_read); } int diff --git a/main.h b/main.h index 688dbe2..aa3ccf1 100644 --- a/main.h +++ b/main.h @@ -145,10 +145,10 @@ struct cfg { bool do_igmp; char *igmp_iface; - struct uring_ev *uev; + struct uring_ev *uring; struct server_cfg_monitor *server_cfg_monitor; - struct signalfd_ev *sev; - struct announce *aev; + struct signalfd_ev *signal; + struct announce *announce; struct igmp *igmp; struct idle *idle; struct sd_bus *sd_bus; diff --git a/uring.c b/uring.c index e923947..31dfe26 100644 --- a/uring.c +++ b/uring.c @@ -33,10 +33,10 @@ get_sqe(struct uring_task *task) assert_die(task, "invalid arguments"); - sqe = io_uring_get_sqe(&cfg->uev->uring); + sqe = io_uring_get_sqe(&cfg->uring->uring); if (!sqe) { - io_uring_submit(&cfg->uev->uring); - sqe = io_uring_get_sqe(&cfg->uev->uring); + io_uring_submit(&cfg->uring->uring); + sqe = io_uring_get_sqe(&cfg->uring->uring); if (!sqe) die("failed to get an sqe!"); } @@ -203,9 +203,9 @@ uring_task_close_fd(struct uring_task *task) struct uring_task * uring_parent() { - assert_die(cfg->uev, "invalid arguments"); + assert_die(cfg->uring, "invalid arguments"); - return &cfg->uev->task; + return &cfg->uring->task; } void @@ -558,24 +558,24 @@ uring_poll_cancel(struct uring_task *task) static void uring_free(struct uring_task *task) { - struct uring_ev *uev = container_of(task, struct uring_ev, task); + struct uring_ev *uring = container_of(task, struct uring_ev, task); assert_return(task); debug(DBG_UR, "task %s (%p), fd %i, refcount %u", task->name, task, task->fd, task->refcount); - io_uring_queue_exit(&uev->uring); - cfg->uev = NULL; - xfree(uev); + io_uring_queue_exit(&uring->uring); + cfg->uring = NULL; + xfree(uring); } void uring_refdump() { - assert_return(cfg->uev); + assert_return(cfg->uring); - uring_task_refdump(&cfg->uev->task); + uring_task_refdump(&cfg->uring->task); } void @@ -583,9 +583,9 @@ uring_delete() { struct uring_task *task; - assert_return(cfg->uev); + assert_return(cfg->uring); - task = &cfg->uev->task; + task = &cfg->uring->task; debug(DBG_UR, "task %s (%p), fd %i, refcount %u", task->name, task, task->fd, task->refcount); @@ -595,20 +595,22 @@ uring_delete() void uring_init() { - struct uring_ev *uev; + struct uring_ev *uring; - uev = zmalloc(sizeof(*uev)); - if (!uev) + assert_return(!cfg->uring); + + uring = zmalloc(sizeof(*uring)); + if (!uring) die("malloc: %m"); - if (io_uring_queue_init_params(4096, &uev->uring, &uev->uring_params) < 0) + if (io_uring_queue_init_params(4096, &uring->uring, &uring->uring_params) < 0) die("io_uring_queue_init_params"); debug(DBG_UR, "uring initialized, features: 0x%08x", - uev->uring_params.features); + uring->uring_params.features); - uring_task_init(&uev->task, "io_uring", &cfg->task, uring_free); - cfg->uev = uev; + uring_task_init(&uring->task, "io_uring", &cfg->task, uring_free); + cfg->uring = uring; } static inline void @@ -636,8 +638,8 @@ uring_event_loop() unsigned nr, head; int r; - io_uring_submit(&cfg->uev->uring); - r = io_uring_wait_cqe(&cfg->uev->uring, &cqe); + io_uring_submit(&cfg->uring->uring); + r = io_uring_wait_cqe(&cfg->uring->uring, &cqe); if (r < 0) { if (errno == EINTR) continue; @@ -646,7 +648,7 @@ uring_event_loop() } nr = 0; - io_uring_for_each_cqe(&cfg->uev->uring, head, cqe) { + io_uring_for_each_cqe(&cfg->uring->uring, head, cqe) { struct uring_task *task = io_uring_cqe_get_data(cqe); bool do_cb; enum cqe_type cqe_type; @@ -695,7 +697,7 @@ uring_event_loop() nr++; } - io_uring_cq_advance(&cfg->uev->uring, nr); + io_uring_cq_advance(&cfg->uring->uring, nr); } } -- cgit v1.2.3