From e11014c0443ea687ad65a14b9124aa366da7984a Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sat, 20 Jun 2020 12:53:25 +0200 Subject: Introduce helper for checking if a task is dead --- rcon.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'rcon.c') diff --git a/rcon.c b/rcon.c index 33fcdb7..e7c37ce 100644 --- a/rcon.c +++ b/rcon.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "main.h" #include "uring.h" @@ -123,7 +124,8 @@ enum rcon_packet_type { }; static void -create_packet(struct cfg *cfg, struct rcon *rcon, int32_t reqid, enum rcon_packet_type type, const char *msg) +create_packet(struct cfg *cfg, struct rcon *rcon, int32_t reqid, + enum rcon_packet_type type, const char *msg) { char *pos = &rcon->tbuf.buf[4]; @@ -150,6 +152,8 @@ packet_complete(struct cfg *cfg, struct uring_task *task, int res) size_t len = task->tbuf->len; int32_t plen; + assert_task_alive_or(DBG_RCON, task, return -EINTR); + if (task->tbuf->len < 14) return 0; @@ -212,10 +216,7 @@ rcon_stop_reply(struct cfg *cfg, struct uring_task *task, int res) int32_t type; char *msg; - if (task->dead) { - debug(DBG_RCON, "task dead\n"); - return; - } + assert_task_alive(DBG_RCON, task); if (res < 0) { debug(DBG_RCON, "res: %i\n", res); @@ -244,10 +245,7 @@ rcon_stop_sent(struct cfg *cfg, struct uring_task *task, int res) { struct rcon *rcon = container_of(task, struct rcon, task); - if (task->dead) { - debug(DBG_RCON, "task dead\n"); - return; - } + assert_task_alive(DBG_RCON, task); if (res < 0) { debug(DBG_RCON, "res: %i\n", res); @@ -267,10 +265,7 @@ rcon_login_reply(struct cfg *cfg, struct uring_task *task, int res) int32_t type; char *msg; - if (task->dead) { - debug(DBG_RCON, "task dead\n"); - return; - } + assert_task_alive(DBG_RCON, task); if (res < 0) { debug(DBG_RCON, "res: %i\n", res); @@ -305,10 +300,7 @@ rcon_login_sent(struct cfg *cfg, struct uring_task *task, int res) { struct rcon *rcon = container_of(task, struct rcon, task); - if (task->dead) { - debug(DBG_RCON, "task dead\n"); - return; - } + assert_task_alive(DBG_RCON, task); if (res < 0) { debug(DBG_RCON, "res: %i\n", res); @@ -325,9 +317,12 @@ rcon_connected_cb(struct cfg *cfg, struct connection *conn, bool connected) { struct rcon *rcon = container_of(conn, struct rcon, conn); + assert_task_alive(DBG_RCON, &rcon->task); + if (!connected) { error("rcon connection to remote server (%s) failed\n", rcon->server->name); + uring_task_put(cfg, &rcon->task); return; } -- cgit v1.2.3