diff --git a/include/zenoh-pico/net/query.h b/include/zenoh-pico/net/query.h index 82dbe9d8c..433fc1217 100644 --- a/include/zenoh-pico/net/query.h +++ b/include/zenoh-pico/net/query.h @@ -44,6 +44,7 @@ static inline bool _z_query_check(const _z_query_t *query) { return _z_keyexpr_check(&query->_key) || _z_value_check(&query->_value) || _z_bytes_check(&query->_attachment) || _z_string_check(&query->_parameters); } +z_result_t _z_query_send_reply_final(_z_query_t *q); void _z_query_clear(_z_query_t *q); z_result_t _z_query_copy(_z_query_t *dst, const _z_query_t *src); void _z_query_free(_z_query_t **query); diff --git a/src/net/query.c b/src/net/query.c index dcf5b647a..e1748e8c8 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -17,7 +17,7 @@ #include "zenoh-pico/transport/common/tx.h" #include "zenoh-pico/utils/logging.h" -void _z_query_clear_inner(_z_query_t *q) { +static void _z_query_clear_inner(_z_query_t *q) { _z_keyexpr_clear(&q->_key); _z_value_clear(&q->_value); _z_bytes_drop(&q->_attachment); @@ -25,15 +25,20 @@ void _z_query_clear_inner(_z_query_t *q) { _z_session_rc_drop(&q->_zn); } +z_result_t _z_query_send_reply_final(_z_query_t *q) { + if (_Z_RC_IS_NULL(&q->_zn)) { + return _Z_ERR_TRANSPORT_TX_FAILED; + } + _z_zenoh_message_t z_msg = _z_n_msg_make_response_final(q->_request_id); + z_result_t ret = _z_send_n_msg(_Z_RC_IN_VAL(&q->_zn), &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK); + _z_msg_clear(&z_msg); + return ret; +} + void _z_query_clear(_z_query_t *q) { - if (!_Z_RC_IS_NULL(&q->_zn)) { - // Send REPLY_FINAL message - _z_zenoh_message_t z_msg = _z_n_msg_make_response_final(q->_request_id); - if (_z_send_n_msg(_Z_RC_IN_VAL(&q->_zn), &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != - _Z_RES_OK) { - _Z_ERROR("Query send REPLY_FINAL transport failure !"); - } - _z_msg_clear(&z_msg); + // Send REPLY_FINAL message + if (_z_query_send_reply_final(q) != _Z_RES_OK) { + _Z_ERROR("Query send REPLY_FINAL transport failure !"); } // Clean up memory _z_query_clear_inner(q); diff --git a/src/session/queryable.c b/src/session/queryable.c index d3b120751..06d81c647 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -231,6 +231,8 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer _z_queryable_infos_t *qle_info = _z_queryable_infos_svec_get(&qles, i); qle_info->callback(&query, qle_info->arg); } + // Send reply final message + _z_query_send_reply_final(&query); // Clean up _z_keyexpr_clear(&key); #if Z_FEATURE_RX_CACHE != 1