Skip to content

Commit

Permalink
fix: reset dbuf instead of clear
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Dec 4, 2024
1 parent 6da6c45 commit 3fa9b5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
24 changes: 10 additions & 14 deletions src/transport/multicast/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,18 @@ z_result_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm,
}
entry->_received = true;

bool consecutive;
_z_wbuf_t *dbuf;
// Check if the SN is correct and select the right defragmentation buffer
if (_Z_HAS_FLAG(t_msg->_header, _Z_FLAG_T_FRAME_R)) {
// @TODO: amend once reliability is in place. For the time being only
// monotonic SNs are ensured
if (_z_sn_precedes(entry->_sn_res, entry->_sn_rx_sns._val._plain._reliable,
t_msg->_body._fragment._sn) == true) {
bool consecutive = _z_sn_consecutive(entry->_sn_res, entry->_sn_rx_sns._val._plain._reliable,
consecutive = _z_sn_consecutive(entry->_sn_res, entry->_sn_rx_sns._val._plain._reliable,
t_msg->_body._fragment._sn);
entry->_sn_rx_sns._val._plain._reliable = t_msg->_body._fragment._sn;
dbuf = &entry->_dbuf_reliable;
if (!consecutive) {
_Z_DEBUG("Non-consecutive fragments received");
_z_wbuf_reset(dbuf);
break;
}
} else {
_z_wbuf_clear(&entry->_dbuf_reliable);
_Z_INFO("Reliable message dropped because it is out of order");
Expand All @@ -212,31 +208,31 @@ z_result_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm,
} else {
if (_z_sn_precedes(entry->_sn_res, entry->_sn_rx_sns._val._plain._best_effort,
t_msg->_body._fragment._sn)) {
bool consecutive = _z_sn_consecutive(entry->_sn_res, entry->_sn_rx_sns._val._plain._best_effort,
consecutive = _z_sn_consecutive(entry->_sn_res, entry->_sn_rx_sns._val._plain._best_effort,
t_msg->_body._fragment._sn);
entry->_sn_rx_sns._val._plain._best_effort = t_msg->_body._fragment._sn;
dbuf = &entry->_dbuf_best_effort;
if (!consecutive) {
_Z_DEBUG("Non-consecutive fragments received");
_z_wbuf_reset(dbuf);
break;
}
} else {
_z_wbuf_clear(&entry->_dbuf_best_effort);
_Z_INFO("Best effort message dropped because it is out of order");
break;
}
}
if (!consecutive && _z_wbuf_len(dbuf) > 0) {
_Z_DEBUG("Non-consecutive fragments received");
_z_wbuf_reset(dbuf);
break;
}
// Handle fragment markers
if (_Z_PATCH_HAS_FRAGMENT_MARKERS(entry->_patch)) {
if (t_msg->_body._fragment.first) {
_z_wbuf_clear(dbuf);
_z_wbuf_reset(dbuf);
} else if (_z_wbuf_len(dbuf) == 0) {
_Z_DEBUG("First fragment received without the first marker");
break;
}
if (t_msg->_body._fragment.drop) {
_z_wbuf_clear(dbuf);
_z_wbuf_reset(dbuf);
break;
}
}
Expand Down
24 changes: 10 additions & 14 deletions src/transport/unicast/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,53 +141,49 @@ z_result_t _z_unicast_handle_transport_message(_z_transport_unicast_t *ztu, _z_t
case _Z_MID_T_FRAGMENT: {
_Z_INFO("Received Z_FRAGMENT message");
#if Z_FEATURE_FRAGMENTATION == 1
bool consecutive;
_z_wbuf_t *dbuf;
// Check if the SN is correct and select the right defragmentation buffer
if (_Z_HAS_FLAG(t_msg->_header, _Z_FLAG_T_FRAME_R)) {
// @TODO: amend once reliability is in place. For the time being only
// monotonic SNs are ensured
if (_z_sn_precedes(ztu->_sn_res, ztu->_sn_rx_reliable, t_msg->_body._fragment._sn)) {
bool consecutive =
consecutive =
_z_sn_consecutive(ztu->_sn_res, ztu->_sn_rx_reliable, t_msg->_body._fragment._sn);
ztu->_sn_rx_reliable = t_msg->_body._fragment._sn;
dbuf = &ztu->_dbuf_reliable;
if (!consecutive) {
_Z_DEBUG("Non-consecutive fragments received");
_z_wbuf_reset(dbuf);
break;
}
} else {
_z_wbuf_clear(&ztu->_dbuf_reliable);
_Z_INFO("Reliable message dropped because it is out of order");
break;
}
} else {
if (_z_sn_precedes(ztu->_sn_res, ztu->_sn_rx_best_effort, t_msg->_body._fragment._sn)) {
bool consecutive =
consecutive =
_z_sn_consecutive(ztu->_sn_res, ztu->_sn_rx_best_effort, t_msg->_body._fragment._sn);
ztu->_sn_rx_best_effort = t_msg->_body._fragment._sn;
dbuf = &ztu->_dbuf_best_effort;
if (!consecutive) {
_Z_DEBUG("Non-consecutive fragments received");
_z_wbuf_reset(dbuf);
break;
}
} else {
_z_wbuf_clear(&ztu->_dbuf_best_effort);
_Z_INFO("Best effort message dropped because it is out of order");
break;
}
}
if (!consecutive && _z_wbuf_len(dbuf) > 0) {
_Z_DEBUG("Non-consecutive fragments received");
_z_wbuf_reset(dbuf);
break;
}
// Handle fragment markers
if (_Z_PATCH_HAS_FRAGMENT_MARKERS(ztu->_patch)) {
if (t_msg->_body._fragment.first) {
_z_wbuf_clear(dbuf);
_z_wbuf_reset(dbuf);
} else if (_z_wbuf_len(dbuf) == 0) {
_Z_DEBUG("First fragment received without the start marker");
break;
}
if (t_msg->_body._fragment.drop) {
_z_wbuf_clear(dbuf);
_z_wbuf_reset(dbuf);
break;
}
}
Expand Down

0 comments on commit 3fa9b5d

Please sign in to comment.