diff options
-rw-r--r-- | announce.c | 1 | ||||
-rw-r--r-- | main.c | 30 | ||||
-rw-r--r-- | main.h | 2 | ||||
-rw-r--r-- | uring.c | 22 | ||||
-rw-r--r-- | uring.h | 2 |
5 files changed, 47 insertions, 10 deletions
@@ -118,6 +118,7 @@ announce_delete(struct cfg *cfg) fprintf(stderr, "%s called, closing fd %i\n", __func__, cfg->aev->task.fd); uring_cancel(cfg, &cfg->aev->task); + uring_task_put(cfg, &cfg->aev->mcast_task); cfg->aev = NULL; } @@ -22,6 +22,10 @@ int debuglvl = 0; +bool exiting = false; + +struct cfg *cfghack = NULL; + void debug(unsigned lvl, const char *fmt, ...) { @@ -57,8 +61,10 @@ cfg_free(struct uring_task *task) { struct cfg *cfg = container_of(task, struct cfg, task); + fprintf(stderr, "%s: called\n", __func__); free(cfg); - exit(EXIT_SUCCESS); + fprintf(stderr, "All resources free, exiting\n"); + exiting = true; } static void @@ -134,6 +140,7 @@ cfg_init(int argc, char **argv) struct signalfd_ev { struct uring_task task; //struct signalfd_siginfo buf; + struct cfg *cfg; uint64_t buf; }; @@ -142,7 +149,8 @@ signalfd_free(struct uring_task *task) { struct signalfd_ev *sev = container_of(task, struct signalfd_ev, task); - debug(2, "Freeing signalfd\n"); + fprintf(stderr, "%s: called\n", __func__); + sev->cfg->sev = NULL; free(sev); } @@ -156,7 +164,8 @@ dump_tree(struct cfg *cfg) fprintf(stderr, "============\n"); uring_task_refdump(&cfg->task); uring_refdump(cfg->uev); - uring_task_refdump(&cfg->sev->task); + if (cfg->sev) + uring_task_refdump(&cfg->sev->task); announce_refdump(cfg->aev); if (cfg->iev) cfgdir_refdump(cfg->iev); @@ -190,7 +199,9 @@ signalfd_read(struct cfg *cfg, struct uring_task *task, int res) cfgdir_delete(cfg); list_for_each_entry_safe(server, stmp, &cfg->servers, list) server_delete(cfg, server); - uring_read(cfg, &sev->task, &sev->buf, sizeof(sev->buf), 0, signalfd_read); + fprintf(stderr, "%s: putting sev task 0x%p\n", __func__, &sev->task); + uring_task_put(cfg, &sev->task); + //uring_read(cfg, &sev->task, &sev->buf, sizeof(sev->buf), 0, signalfd_read); } } @@ -200,11 +211,14 @@ static void hack_handler(int signum) { uint64_t val; + static int count = 0; switch (signum) { case SIGINT: fprintf(stderr, "Got a SIGINT\n"); val = 1000; + if (count > 3) + dump_tree(cfghack); break; case SIGHUP: fprintf(stderr, "Got a SIGHUP\n"); @@ -221,6 +235,7 @@ hack_handler(int signum) } write(hack_efd, &val, sizeof(val)); + count++; } static void @@ -264,6 +279,7 @@ signalfd_init(struct cfg *cfg) uring_task_init(&sev->task, "sev", uring_parent(cfg), signalfd_free); uring_task_set_fd(&sev->task, sfd); cfg->sev = sev; + sev->cfg = cfg; hack_efd = sfd; uring_read(cfg, &sev->task, &sev->buf, sizeof(sev->buf), 0, signalfd_read); } @@ -275,6 +291,8 @@ main(int argc, char **argv) cfg = cfg_init(argc, argv); + cfghack = cfg; + cfg_read(cfg); uring_init(cfg); @@ -287,7 +305,11 @@ main(int argc, char **argv) announce_start(cfg->aev); + uring_task_put(cfg, &cfg->task); + uring_event_loop(cfg); + fprintf(stderr, "Event loop exited\n"); + exit(EXIT_SUCCESS); } @@ -5,6 +5,8 @@ #include <netinet/ip.h> #include "utils.h" +extern bool exiting; + extern int debuglvl; void debug(unsigned lvl, const char *fmt, ...); @@ -12,6 +12,7 @@ struct uring_ev { struct io_uring uring; struct io_uring_params uring_params; + struct cfg *cfg; struct uring_task task; }; @@ -271,7 +272,13 @@ uring_cancel(struct cfg *cfg, struct uring_task *task) static void uring_free(struct uring_task *task) { - fprintf(stderr, "%s called\n", __func__); + struct uring_ev *uev = container_of(task, struct uring_ev, task); + + fprintf(stderr, "%s: called\n", __func__); + + io_uring_queue_exit(&uev->uring); + uev->cfg->uev = NULL; + free(uev); } void @@ -296,9 +303,10 @@ uring_init(struct cfg *cfg) uring_task_init(&uev->task, "uev", &cfg->task, uring_free); cfg->uev = uev; + uev->cfg = cfg; } -int +void uring_event_loop(struct cfg *cfg) { while (true) { @@ -320,17 +328,21 @@ uring_event_loop(struct cfg *cfg) struct uring_task *task = io_uring_cqe_get_data(cqe); fprintf(stderr, "%s: got CEQ (res: %i, task: 0x%p, cb: 0x%p)\n", __func__, cqe->res, task, task ? task->callback : NULL); + if (task && task->callback) task->callback(cfg, task, cqe->res); - nr++; + if (task) uring_task_put(cfg, task); + + if (exiting) + return; + + nr++; } printf("%s: %u CQEs treated\n", __func__, nr); io_uring_cq_advance(&cfg->uev->uring, nr); } - - return 0; } @@ -44,6 +44,6 @@ void uring_refdump(struct uring_ev *uev); void uring_init(struct cfg *cfg); -int uring_event_loop(struct cfg *cfg); +void uring_event_loop(struct cfg *cfg); #endif |