-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,30 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
|
||
#include <ctype.h> | ||
#include <errno.h> | ||
#include <pthread.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <zenoh-pico.h> | ||
|
||
#if Z_FEATURE_QUERY == 1 | ||
#define QUERY_TIMEOUT 10 // query timeout in seconds | ||
#define handle_error_en(en, msg) \ | ||
do { \ | ||
errno = en; \ | ||
perror(msg); \ | ||
exit(EXIT_FAILURE); \ | ||
} while (0) | ||
pthread_cond_t cond; | ||
pthread_mutex_t mutex; | ||
|
||
void reply_dropper(void *ctx) { | ||
(void)(ctx); | ||
printf(">> Received query final notification\n"); | ||
pthread_cond_signal(&cond); | ||
pthread_cond_destroy(&cond); | ||
} | ||
|
||
void reply_handler(z_owned_reply_t *reply, void *ctx) { | ||
|
@@ -73,6 +87,9 @@ int main(int argc, char **argv) { | |
} | ||
} | ||
|
||
pthread_mutex_init(&mutex, NULL); | ||
pthread_cond_init(&cond, NULL); | ||
|
||
z_owned_config_t config = z_config_default(); | ||
zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode)); | ||
if (clocator != NULL) { | ||
|
@@ -102,6 +119,7 @@ int main(int argc, char **argv) { | |
return -1; | ||
} | ||
|
||
pthread_mutex_lock(&mutex); | ||
printf("Sending Query '%s'...\n", keyexpr); | ||
z_get_options_t opts = z_get_options_default(); | ||
if (value != NULL) { | ||
|
@@ -112,6 +130,14 @@ int main(int argc, char **argv) { | |
printf("Unable to send query.\n"); | ||
return -1; | ||
} | ||
struct timespec query_timeout; | ||
clock_gettime(CLOCK_REALTIME, &query_timeout); | ||
query_timeout.tv_sec += QUERY_TIMEOUT; | ||
int err = pthread_cond_timedwait(&cond, &mutex, &query_timeout); | ||
if (err != 0) { | ||
handle_error_en(err, "pthread_cond_timedwait"); | ||
} | ||
pthread_mutex_unlock(&mutex); | ||
|
||
// Stop read and lease tasks for zenoh-pico | ||
zp_stop_read_task(z_loan(s)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,16 +12,30 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
|
||
#include <ctype.h> | ||
#include <errno.h> | ||
#include <pthread.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <zenoh-pico.h> | ||
|
||
#if Z_FEATURE_QUERY == 1 | ||
#define QUERY_TIMEOUT 10 // query timeout in seconds | ||
#define handle_error_en(en, msg) \ | ||
do { \ | ||
errno = en; \ | ||
perror(msg); \ | ||
exit(EXIT_FAILURE); \ | ||
} while (0) | ||
pthread_cond_t cond; | ||
pthread_mutex_t mutex; | ||
|
||
void reply_dropper(void *ctx) { | ||
(void)(ctx); | ||
printf(">> Received query final notification\n"); | ||
pthread_cond_signal(&cond); | ||
pthread_cond_destroy(&cond); | ||
} | ||
|
||
void reply_handler(z_owned_reply_t *reply, void *ctx) { | ||
|
@@ -73,6 +87,9 @@ int main(int argc, char **argv) { | |
} | ||
} | ||
|
||
pthread_mutex_init(&mutex, NULL); | ||
pthread_cond_init(&cond, NULL); | ||
|
||
z_owned_config_t config = z_config_default(); | ||
zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode)); | ||
if (clocator != NULL) { | ||
|
@@ -102,6 +119,7 @@ int main(int argc, char **argv) { | |
return -1; | ||
} | ||
|
||
pthread_mutex_lock(&mutex); | ||
printf("Sending Query '%s'...\n", keyexpr); | ||
z_get_options_t opts = z_get_options_default(); | ||
if (value != NULL) { | ||
|
@@ -112,6 +130,14 @@ int main(int argc, char **argv) { | |
printf("Unable to send query.\n"); | ||
return -1; | ||
} | ||
struct timespec query_timeout; | ||
clock_gettime(CLOCK_REALTIME, &query_timeout); | ||
query_timeout.tv_sec += QUERY_TIMEOUT; | ||
int err = pthread_cond_timedwait(&cond, &mutex, &query_timeout); | ||
if (err != 0) { | ||
handle_error_en(err, "pthread_cond_timedwait"); | ||
} | ||
pthread_mutex_unlock(&mutex); | ||
|
||
// Stop read and lease tasks for zenoh-pico | ||
zp_stop_read_task(z_session_loan(&s)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,29 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
|
||
#include <ctype.h> | ||
#include <errno.h> | ||
#include <pthread.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <zenoh-pico.h> | ||
|
||
#if Z_FEATURE_QUERY == 1 | ||
#define QUERY_TIMEOUT 10 // query timeout in seconds | ||
#define handle_error_en(en, msg) \ | ||
do { \ | ||
errno = en; \ | ||
perror(msg); \ | ||
exit(EXIT_FAILURE); \ | ||
} while (0) | ||
pthread_cond_t cond; | ||
pthread_mutex_t mutex; | ||
|
||
void reply_dropper(void *ctx) { | ||
(void)(ctx); | ||
printf(">> Received query final notification\n"); | ||
pthread_cond_signal(&cond); | ||
pthread_cond_destroy(&cond); | ||
} | ||
|
||
void reply_handler(z_owned_reply_t *reply, void *ctx) { | ||
|
@@ -42,6 +56,9 @@ int main(int argc, char **argv) { | |
const char *locator = NULL; | ||
const char *value = NULL; | ||
|
||
pthread_mutex_init(&mutex, NULL); | ||
pthread_cond_init(&cond, NULL); | ||
|
||
z_owned_config_t config = z_config_default(); | ||
if (locator != NULL) { | ||
zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(locator)); | ||
|
@@ -67,6 +84,7 @@ int main(int argc, char **argv) { | |
return -1; | ||
} | ||
|
||
pthread_mutex_lock(&mutex); | ||
printf("Sending Query '%s'...\n", keyexpr); | ||
z_get_options_t opts = z_get_options_default(); | ||
if (value != NULL) { | ||
|
@@ -77,6 +95,14 @@ int main(int argc, char **argv) { | |
printf("Unable to send query.\n"); | ||
return -1; | ||
} | ||
struct timespec query_timeout; | ||
clock_gettime(CLOCK_REALTIME, &query_timeout); | ||
query_timeout.tv_sec += QUERY_TIMEOUT; | ||
int err = pthread_cond_timedwait(&cond, &mutex, &query_timeout); | ||
if (err != 0) { | ||
handle_error_en(err, "pthread_cond_timedwait"); | ||
} | ||
pthread_mutex_unlock(&mutex); | ||
|
||
// Stop read and lease tasks for zenoh-pico | ||
zp_stop_read_task(z_loan(s)); | ||
|