Skip to content

Commit

Permalink
fix: queryables issues (#22)
Browse files Browse the repository at this point in the history
* fix: queryables issues

* fix: explicit query data stealking
  • Loading branch information
jean-roland authored Dec 4, 2024
1 parent e530209 commit 5381f9b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/collections/bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ z_result_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src) {

_z_bytes_t _z_bytes_alias(const _z_bytes_t src) {
_z_bytes_t dst;
dst._slices = _z_arc_slice_svec_alias(&src._slices);
dst._slices = src._slices;
return dst;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _z_encoding_t _z_encoding_alias(_z_encoding_t src) {
_z_encoding_t dst;
dst.id = src.id;
if (_z_string_check(&src.schema)) {
_z_string_alias(src.schema);
dst.schema = _z_string_alias(src.schema);
} else {
dst.schema = _z_string_null();
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void _z_query_clear_inner(_z_query_t *q) {
z_result_t _z_query_send_reply_final(_z_query_t *q) {
// Try to upgrade session weak to rc
_z_session_rc_t sess_rc = _z_session_weak_upgrade_if_open(&q->_zn);
if (!_Z_RC_IS_NULL(&sess_rc)) {
if (_Z_RC_IS_NULL(&sess_rc)) {
return _Z_ERR_TRANSPORT_TX_FAILED;
}
_z_zenoh_message_t z_msg = _z_n_msg_make_response_final(q->_request_id);
Expand Down
26 changes: 20 additions & 6 deletions src/session/queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,16 @@ static z_result_t _z_session_queryable_get_infos(_z_session_t *zn, const _z_keye
return _Z_RES_OK;
}

static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, const _z_keyexpr_t *q_key,
static inline void _z_queryable_query_steal_data(_z_query_t *query, _z_session_rc_t *zsrc, _z_msg_query_t *msgq,
_z_keyexpr_t *key, uint32_t qid, bool anyke) {
// Steal received data in query
*query = _z_query_alias(&msgq->_ext_value, key, &msgq->_parameters, zsrc, qid, &msgq->_ext_attachment, anyke);
msgq->_ext_value = _z_value_null();
msgq->_ext_attachment = _z_bytes_null();
msgq->_parameters = _z_slice_null();
}

static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z_keyexpr_t *q_key,
uint32_t qid) {
_z_session_t *zn = _Z_RC_IN_VAL(zsrc);
_z_keyexpr_t key;
Expand All @@ -224,9 +233,15 @@ static z_result_t _z_trigger_queryables_inner(_z_session_rc_t *zsrc, _z_msg_quer
}
}
// Build the z_query
_z_query_t q =
_z_query_alias(&msgq->_ext_value, &key, &msgq->_parameters, zsrc, qid, &msgq->_ext_attachment, anyke);
_z_query_rc_t query = _z_query_rc_new_from_val(&q);
_z_query_t *q = z_malloc(sizeof(_z_query_t));
if (q == NULL) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
_z_query_rc_t query = _z_query_rc_new(q);
if (_Z_RC_IS_NULL(&query)) {
return _Z_ERR_SYSTEM_OUT_OF_MEMORY;
}
_z_queryable_query_steal_data(q, zsrc, msgq, &key, qid, anyke);
// Parse session_queryable svec
for (size_t i = 0; i < qle_nb; i++) {
_z_queryable_infos_t *qle_info = _z_queryable_infos_svec_get(&qles, i);
Expand All @@ -245,8 +260,7 @@ z_result_t _z_trigger_queryables(_z_session_rc_t *zsrc, _z_msg_query_t *msgq, _z
z_result_t ret = _z_trigger_queryables_inner(zsrc, msgq, q_key, qid);
// Clean up
_z_keyexpr_clear(q_key);
_z_encoding_clear(&msgq->_ext_value.encoding);
_z_bytes_drop(&msgq->_ext_value.payload);
_z_value_clear(&msgq->_ext_value);
_z_bytes_drop(&msgq->_ext_attachment);
_z_slice_clear(&msgq->_parameters);
return ret;
Expand Down

0 comments on commit 5381f9b

Please sign in to comment.