From 991fb93e65cb46050302349be30e00152fd1ef6e Mon Sep 17 00:00:00 2001 From: Jean-Roland Gosse Date: Mon, 8 Jan 2024 14:47:53 +0100 Subject: [PATCH] Leave null pointer if task init failed & stop unicast read task when close message received (#306) * fix: stop unicast read task if close message received * fix: leave null pointer if task init failed --- include/zenoh-pico/utils/result.h | 2 ++ src/transport/multicast/lease.c | 7 +++---- src/transport/multicast/read.c | 7 +++---- src/transport/raweth/read.c | 7 +++---- src/transport/unicast/lease.c | 7 +++---- src/transport/unicast/read.c | 7 +++---- src/transport/unicast/rx.c | 5 ++++- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/zenoh-pico/utils/result.h b/include/zenoh-pico/utils/result.h index 514473947..a3ff7c1d6 100644 --- a/include/zenoh-pico/utils/result.h +++ b/include/zenoh-pico/utils/result.h @@ -65,6 +65,8 @@ typedef enum { _Z_ERR_SYSTEM_TASK_FAILED = -79, _Z_ERR_SYSTEM_OUT_OF_MEMORY = -78, + _Z_ERR_CONNECTION_CLOSED = -77, + _Z_ERR_GENERIC = -128 } _z_res_t; diff --git a/src/transport/multicast/lease.c b/src/transport/multicast/lease.c index 8ab532bee..2d3a0d496 100644 --- a/src/transport/multicast/lease.c +++ b/src/transport/multicast/lease.c @@ -184,14 +184,13 @@ void *_zp_multicast_lease_task(void *ztm_arg) { int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - ztm->_lease_task = task; - ztm->_lease_task_running = true; // Init task if (_z_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) { - ztm->_lease_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } + // Attach task + ztm->_lease_task = task; + ztm->_lease_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/multicast/read.c b/src/transport/multicast/read.c index 8081d1fcc..6d50f580d 100644 --- a/src/transport/multicast/read.c +++ b/src/transport/multicast/read.c @@ -131,14 +131,13 @@ void *_zp_multicast_read_task(void *ztm_arg) { int8_t _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._multicast._read_task = task; - zt->_transport._multicast._read_task_running = true; // Init task if (_z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) { - zt->_transport._multicast._read_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } + // Attach task + zt->_transport._multicast._read_task = task; + zt->_transport._multicast._read_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/raweth/read.c b/src/transport/raweth/read.c index 49680e6b0..11cb7141a 100644 --- a/src/transport/raweth/read.c +++ b/src/transport/raweth/read.c @@ -86,14 +86,13 @@ void *_zp_raweth_read_task(void *ztm_arg) { int8_t _zp_raweth_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._raweth._read_task = task; - zt->_transport._raweth._read_task_running = true; // Init task if (_z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) { - zt->_transport._raweth._read_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } + // Attach task + zt->_transport._raweth._read_task = task; + zt->_transport._raweth._read_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/unicast/lease.c b/src/transport/unicast/lease.c index 5ef50565b..cd63416f5 100644 --- a/src/transport/unicast/lease.c +++ b/src/transport/unicast/lease.c @@ -98,14 +98,13 @@ void *_zp_unicast_lease_task(void *ztu_arg) { int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._unicast._lease_task = task; - zt->_transport._unicast._lease_task_running = true; // Init task if (_z_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) { - zt->_transport._unicast._lease_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } + // Attach task + zt->_transport._unicast._lease_task = task; + zt->_transport._unicast._lease_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/unicast/read.c b/src/transport/unicast/read.c index a62fa2474..36598118a 100644 --- a/src/transport/unicast/read.c +++ b/src/transport/unicast/read.c @@ -124,14 +124,13 @@ void *_zp_unicast_read_task(void *ztu_arg) { int8_t _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Attach task - zt->_transport._unicast._read_task = task; - zt->_transport._unicast._read_task_running = true; // Init task if (_z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) { - zt->_transport._unicast._read_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } + // Attach task + zt->_transport._unicast._read_task = task; + zt->_transport._unicast._read_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/unicast/rx.c b/src/transport/unicast/rx.c index c1e3faa2d..f925600f7 100644 --- a/src/transport/unicast/rx.c +++ b/src/transport/unicast/rx.c @@ -96,6 +96,8 @@ int8_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t } int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) { + int8_t ret = _Z_RES_OK; + switch (_Z_MID(t_msg->_header)) { case _Z_MID_T_FRAME: { _Z_INFO("Received Z_FRAME message\n"); @@ -190,6 +192,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans case _Z_MID_T_CLOSE: { _Z_INFO("Closing session as requested by the remote peer\n"); + ret = _Z_ERR_CONNECTION_CLOSED; break; } @@ -199,7 +202,7 @@ int8_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_trans } } - return _Z_RES_OK; + return ret; } #else int8_t _z_unicast_recv_t_msg(_z_transport_unicast_t *ztu, _z_transport_message_t *t_msg) {