Skip to content

Commit

Permalink
Leave null pointer if task init failed & stop unicast read task when …
Browse files Browse the repository at this point in the history
…close message received (#306)

* fix: stop unicast read task if close message received

* fix: leave null pointer if task init failed
  • Loading branch information
jean-roland authored Jan 8, 2024
1 parent 76a5b4f commit 991fb93
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 2 additions & 0 deletions include/zenoh-pico/utils/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 3 additions & 4 deletions src/transport/multicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/multicast/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/raweth/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions src/transport/unicast/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/transport/unicast/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down

0 comments on commit 991fb93

Please sign in to comment.