Skip to content

Commit

Permalink
fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed May 28, 2024
1 parent 9198c57 commit 8bf9cd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 5 additions & 7 deletions examples/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char **argv) {
expr = argv[1];
break;
case 1:
// Do nothing
value = "Test Value";
break;
}
z_view_keyexpr_t keyexpr;
Expand All @@ -49,7 +49,7 @@ int main(int argc, char **argv) {

printf("Opening session...\n");
z_owned_session_t s;
if (!z_open(&s, z_move(config))) {
if (z_open(&s, z_move(config))) {
printf("Unable to open session!\n");
exit(-1);
}
Expand All @@ -72,18 +72,16 @@ int main(int argc, char **argv) {

for (z_call(z_loan(channel.recv), &reply); z_check(reply); z_call(z_loan(channel.recv), &reply)) {
if (z_reply_is_ok(z_loan(reply))) {
const z_loaned_sample_t* sample = z_reply_ok(z_loan(reply));
const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply));

z_view_str_t key_str;
z_keyexpr_to_string(z_sample_keyexpr(sample), &key_str);

z_owned_str_t reply_str;
z_bytes_decode_into_string(z_sample_payload(sample), &reply_str);

printf(">> Received ('%.*s': '%.*s')\n",
(int)z_str_len(z_loan(key_str)), z_str_data(z_loan(key_str)),
(int)z_str_len(z_loan(reply_str)), z_str_data(z_loan(reply_str))
);
printf(">> Received ('%.*s': '%.*s')\n", (int)z_str_len(z_loan(key_str)), z_str_data(z_loan(key_str)),
(int)z_str_len(z_loan(reply_str)), z_str_data(z_loan(reply_str)));
z_drop(z_move(reply_str));
} else {
printf("Received an error\n");
Expand Down
13 changes: 9 additions & 4 deletions examples/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#define PING_TIMEOUT_SEC 1

#define handle_error_en(en, msg) \
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
do { \
errno = en; \
perror(msg); \
exit(EXIT_FAILURE); \
} while (0)

z_owned_condvar_t cond;
z_owned_mutex_t mutex;
Expand All @@ -38,17 +42,17 @@ int main(int argc, char** argv) {
-w (optional, int, default=%d): the warmup time in ms during which pings will be emitted but not measured\n\
-c (optional, string): the path to a configuration file for the session. If this option isn't passed, the default configuration will be used.\n\
",
DEFAULT_PKT_SIZE, DEFAULT_PING_NB, DEFAULT_WARMUP_MS);
DEFAULT_PING_NB, DEFAULT_PKT_SIZE, DEFAULT_WARMUP_MS);
return 1;
}
z_mutex_init(&mutex);
z_condvar_init(&cond);
z_owned_config_t config;
z_owned_config_t config;
if (args.config_path) {
zc_config_from_file(&config, args.config_path);
} else {
z_config_default(&config);
}
}
z_owned_session_t session;
z_open(&session, z_move(config));
z_view_keyexpr_t ping;
Expand Down Expand Up @@ -85,6 +89,7 @@ int main(int argc, char** argv) {
}
unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings);
for (int i = 0; i < args.number_of_pings; i++) {
z_bytes_encode_from_slice(&payload, data, args.size);
z_clock_t measure_start = z_clock_now();
z_publisher_put(z_loan(pub), z_move(payload), NULL);
int s = z_condvar_wait(z_loan(cond), z_loan_mut(mutex));
Expand Down

0 comments on commit 8bf9cd9

Please sign in to comment.