Skip to content

Commit

Permalink
Expose timeout option in z_get_options_t (#375)
Browse files Browse the repository at this point in the history
* Expose timeout option in z_get_options_t

* Add default get timeout
  • Loading branch information
sashacmc authored Mar 21, 2024
1 parent 9f7925b commit 0d9f25b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions include/zenoh-pico/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ typedef struct {
z_value_t value;
z_query_consolidation_t consolidation;
z_query_target_t target;
uint32_t timeout_ms;
#if Z_FEATURE_ATTACHMENT == 1
// TODO:ATT z_attachment_t attachment;
#endif
Expand Down
7 changes: 7 additions & 0 deletions include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,11 @@
#define ZP_ASM_NOP __asm__("nop")
#endif

/**
* Default get timeout in milliseconds.
*/
#ifndef Z_GET_TIMEOUT_DEFAULT
#define Z_GET_TIMEOUT_DEFAULT 10000
#endif

#endif /* INCLUDE_ZENOH_PICO_CONFIG_H */
2 changes: 1 addition & 1 deletion include/zenoh-pico/net/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ int8_t _z_send_reply(const _z_query_t *query, const _z_keyexpr_t keyexpr, const
*/
int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target,
const z_consolidation_mode_t consolidation, const _z_value_t value, _z_reply_handler_t callback,
void *arg_call, _z_drop_handler_t dropper, void *arg_drop
void *arg_call, _z_drop_handler_t dropper, void *arg_drop, uint32_t timeout_ms
#if Z_FEATURE_ATTACHMENT == 1
,
z_attachment_t attachment
Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ _Z_VEC_DEFINE(_z_network_message, _z_network_message_t)
void _z_msg_fix_mapping(_z_zenoh_message_t *msg, uint16_t mapping);
_z_network_message_t _z_msg_make_pull(_z_keyexpr_t key, _z_zint_t pull_id);
_z_network_message_t _z_msg_make_query(_Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_bytes_t) parameters, _z_zint_t qid,
z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value
z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value,
uint32_t timeout_ms
#if Z_FEATURE_ATTACHMENT == 1
,
z_attachment_t attachment
Expand Down
5 changes: 3 additions & 2 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ z_get_options_t z_get_options_default(void) {
#if Z_FEATURE_ATTACHMENT == 1
// TODO:ATT.attachment = z_attachment_null()
#endif
.timeout_ms = Z_GET_TIMEOUT_DEFAULT
};
}

Expand Down Expand Up @@ -836,7 +837,7 @@ int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owne
}

ret = _z_query(&zs._val.in->val, keyexpr, parameters, opt.target, opt.consolidation.mode, opt.value,
__z_reply_handler, wrapped_ctx, callback->drop, ctx
__z_reply_handler, wrapped_ctx, callback->drop, ctx, opt.timeout_ms
#if Z_FEATURE_ATTACHMENT == 1
,
z_attachment_null()
Expand Down Expand Up @@ -1286,4 +1287,4 @@ z_owned_bytes_map_t z_bytes_map_new(void) { return (z_owned_bytes_map_t){._inner
z_owned_bytes_map_t z_bytes_map_null(void) { return (z_owned_bytes_map_t){._inner = NULL}; }
z_bytes_t z_bytes_from_str(const char *str) { return z_bytes_wrap((const uint8_t *)str, strlen(str)); }
z_bytes_t z_bytes_null(void) { return (z_bytes_t){.len = 0, ._is_alloc = false, .start = NULL}; }
#endif
#endif
11 changes: 6 additions & 5 deletions src/net/primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ int8_t _z_send_reply(const _z_query_t *query, _z_keyexpr_t keyexpr, const _z_val
/*------------------ Query ------------------*/
int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, const z_query_target_t target,
const z_consolidation_mode_t consolidation, _z_value_t value, _z_reply_handler_t callback,
void *arg_call, _z_drop_handler_t dropper, void *arg_drop
void *arg_call, _z_drop_handler_t dropper, void *arg_drop, uint32_t timeout_ms
#if Z_FEATURE_ATTACHMENT == 1
,
z_attachment_t attachment
Expand All @@ -404,12 +404,13 @@ int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters,
ret = _z_register_pending_query(zn, pq); // Add the pending query to the current session
if (ret == _Z_RES_OK) {
_z_bytes_t params = _z_bytes_wrap((uint8_t *)pq->_parameters, strlen(pq->_parameters));
_z_zenoh_message_t z_msg = _z_msg_make_query(&keyexpr, &params, pq->_id, pq->_consolidation, &value
_z_zenoh_message_t z_msg =
_z_msg_make_query(&keyexpr, &params, pq->_id, pq->_consolidation, &value, timeout_ms
#if Z_FEATURE_ATTACHMENT == 1
,
attachment
,
attachment
#endif
);
);

if (_z_send_n_msg(zn, &z_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK) != _Z_RES_OK) {
_z_unregister_pending_query(zn, pq);
Expand Down
5 changes: 3 additions & 2 deletions src/protocol/definitions/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ _z_network_message_t _z_msg_make_pull(_z_keyexpr_t key, _z_zint_t pull_id) {
return ret;
}
_z_zenoh_message_t _z_msg_make_query(_Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_bytes_t) parameters, _z_zint_t qid,
z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value
z_consolidation_mode_t consolidation, _Z_MOVE(_z_value_t) value,
uint32_t timeout_ms
#if Z_FEATURE_ATTACHMENT == 1
,
z_attachment_t attachment
Expand All @@ -192,7 +193,7 @@ _z_zenoh_message_t _z_msg_make_query(_Z_MOVE(_z_keyexpr_t) key, _Z_MOVE(_z_bytes
._ext_budget = 0,
._ext_qos = _Z_N_QOS_DEFAULT,
._ext_target = Z_QUERY_TARGET_BEST_MATCHING,
._ext_timeout_ms = 0,
._ext_timeout_ms = timeout_ms,
._ext_timestamp = _z_timestamp_null(),
},
};
Expand Down

0 comments on commit 0d9f25b

Please sign in to comment.