Skip to content

Commit

Permalink
Remove reading from stdin, align example implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
oteffahi committed Feb 28, 2024
1 parent 1e36616 commit c38dfb5
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 60 deletions.
20 changes: 9 additions & 11 deletions examples/z_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,17 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Enter 'd' to undeclare liveliness token, 'q' to quit...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
} else if (c == 'd') {
printf("Undeclaring liveliness token...\n");
z_drop(z_move(token));
}
printf("Press CTRL-C to undeclare liveliness token and quit...\n");
while (1) {
sleep(1);
}

z_drop(z_move(token));
// LivelinessTokens are automatically closed when dropped
// Use the code below to manually undeclare it if needed
//
// printf("Undeclaring liveliness token...\n");
// z_drop(z_move(token));

z_close(z_move(s));
return 0;
}
1 change: 1 addition & 0 deletions examples/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int main(int argc, char **argv) {
listener = zcu_publisher_matching_listener_callback(z_loan(pub), z_move(callback));
}

printf("Press CTRL-C to quit...\n");
char buf[256];
for (int idx = 0; 1; ++idx) {
sleep(1);
Expand Down
1 change: 1 addition & 0 deletions examples/z_pub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ int main(int argc, char **argv) {
// add some value
z_bytes_map_insert_by_alias(&map, z_bytes_from_str("source"), z_bytes_from_str("C"));

printf("Press CTRL-C to quit...\n");
char buf[256];
char buf_ind[16];
for (int idx = 0; 1; ++idx) {
Expand Down
1 change: 1 addition & 0 deletions examples/z_pub_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Press CTRL-C to quit...\n");
char buf[256];
for (int idx = 0; 1; ++idx) {
sleep(1);
Expand Down
1 change: 1 addition & 0 deletions examples/z_pub_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Press CTRL-C to quit...\n");
for (int idx = 0; true; ++idx) {
zc_owned_shmbuf_t shmbuf = zc_shm_alloc(&manager, 256);
if (!z_check(shmbuf)) {
Expand Down
1 change: 1 addition & 0 deletions examples/z_pub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Press CTRL-C to quit...\n");
while (1) {
z_publisher_put(z_loan(pub), (const uint8_t *)value, len, NULL);
}
Expand Down
14 changes: 5 additions & 9 deletions examples/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Press <enter> to pull data...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
} else {
z_subscriber_pull(z_loan(sub));
}
printf("Press CTRL-C to quit...\n");
for (int idx=0; 1; ++idx) {
sleep(1);
printf("[%4d] Pulling...\n", idx);
z_subscriber_pull(z_loan(sub));
}

z_undeclare_pull_subscriber(z_move(sub));
Expand Down
10 changes: 3 additions & 7 deletions examples/z_query_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Enter 'q' to quit...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

z_drop(z_move(sub));
Expand Down
10 changes: 3 additions & 7 deletions examples/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Enter 'q' to quit...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

z_undeclare_queryable(z_move(qable));
Expand Down
2 changes: 1 addition & 1 deletion examples/z_queryable_with_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("^C to quit...\n");
printf("Press CTRL-C to quit...\n");
z_owned_query_t oquery = z_query_null();
for (z_call(channel.recv, &oquery); z_check(oquery); z_call(channel.recv, &oquery)) {
z_query_t query = z_loan(oquery);
Expand Down
10 changes: 3 additions & 7 deletions examples/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Enter 'q' to quit...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

z_undeclare_subscriber(z_move(sub));
Expand Down
10 changes: 3 additions & 7 deletions examples/z_sub_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Enter 'q' to quit...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

z_undeclare_subscriber(z_move(sub));
Expand Down
10 changes: 3 additions & 7 deletions examples/z_sub_liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,9 @@ int main(int argc, char **argv) {
exit(-1);
}

printf("Enter 'q' to quit...\n");
char c = 0;
while (c != 'q') {
c = getchar();
if (c == -1) {
sleep(1);
}
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

z_undeclare_subscriber(z_move(sub));
Expand Down
13 changes: 9 additions & 4 deletions examples/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
//
#include <stdio.h>
#include <time.h>

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#define sleep(x) Sleep(x * 1000)
#else
#include <unistd.h>
#endif
#include "zenoh.h"

#define N 1000000
Expand Down Expand Up @@ -94,9 +99,9 @@ int main(int argc, char **argv) {
exit(-1);
}

char c = 0;
while (c != 'q') {
c = fgetc(stdin);
printf("Press CTRL-C to quit...\n");
while (1) {
sleep(1);
}

z_undeclare_subscriber(z_move(sub));
Expand Down

0 comments on commit c38dfb5

Please sign in to comment.