Skip to content

Commit

Permalink
Merge pull request #171 from eclipse-zenoh/get_options_timeout
Browse files Browse the repository at this point in the history
timeout parameter added to z_get_options_t
  • Loading branch information
milyin authored Sep 6, 2023
2 parents 831b33b + eab7725 commit d18316e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,13 @@ typedef struct z_value_t {
* z_query_target_t target: The Queryables that should be target of the query.
* z_query_consolidation_t consolidation: The replies consolidation strategy to apply on replies to the query.
* z_value_t value: An optional value to attach to the query.
* uint64_t timeout: The timeout for the query in milliseconds. 0 means default query timeout from zenoh configuration.
*/
typedef struct z_get_options_t {
enum z_query_target_t target;
struct z_query_consolidation_t consolidation;
struct z_value_t value;
uint64_t timeout_ms;
} z_get_options_t;
/**
* An borrowed array of borrowed, zenoh allocated, NULL terminated strings.
Expand Down
6 changes: 6 additions & 0 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,20 @@ pub extern "C" fn z_reply_null() -> z_owned_reply_t {
/// z_query_target_t target: The Queryables that should be target of the query.
/// z_query_consolidation_t consolidation: The replies consolidation strategy to apply on replies to the query.
/// z_value_t value: An optional value to attach to the query.
/// uint64_t timeout: The timeout for the query in milliseconds. 0 means default query timeout from zenoh configuration.
#[repr(C)]
pub struct z_get_options_t {
pub target: z_query_target_t,
pub consolidation: z_query_consolidation_t,
pub value: z_value_t,
pub timeout_ms: u64,
}
#[no_mangle]
pub extern "C" fn z_get_options_default() -> z_get_options_t {
z_get_options_t {
target: QueryTarget::default().into(),
consolidation: QueryConsolidation::default().into(),
timeout_ms: 0,
value: {
z_value_t {
payload: z_bytes_t::empty(),
Expand Down Expand Up @@ -218,6 +221,9 @@ pub unsafe extern "C" fn z_get(
.consolidation(options.consolidation)
.target(options.target.into())
.with_value(&options.value);
if options.timeout_ms != 0 {
q = q.timeout(std::time::Duration::from_millis(options.timeout_ms));
}
}
match q
.callback(move |response| z_closure_reply_call(&closure, &mut response.into()))
Expand Down

0 comments on commit d18316e

Please sign in to comment.