summaryrefslogtreecommitdiff
path: root/rcon.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-20 12:53:25 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-20 12:53:25 +0200
commite11014c0443ea687ad65a14b9124aa366da7984a (patch)
tree8c6642ed187dc71cc672cec9f3459aa75134eaa5 /rcon.c
parentfc25e880dfb1f804742006bcdd15ac70d18b4144 (diff)
Introduce helper for checking if a task is dead
Diffstat (limited to 'rcon.c')
-rw-r--r--rcon.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/rcon.c b/rcon.c
index 33fcdb7..e7c37ce 100644
--- a/rcon.c
+++ b/rcon.c
@@ -8,6 +8,7 @@
#include <arpa/inet.h>
#include <stdint.h>
#include <inttypes.h>
+#include <errno.h>
#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;
}