Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leave null pointer if task init failed & stop unicast read task when close message received #306

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading