diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 10deb3062..35f508de7 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -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. diff --git a/src/get.rs b/src/get.rs index 6229972e9..d0706bed2 100644 --- a/src/get.rs +++ b/src/get.rs @@ -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(), @@ -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()))