From 97779e0f5959e0efbabf85d4f3143ab786e53dfd Mon Sep 17 00:00:00 2001 From: yuanyuyuan Date: Wed, 7 Aug 2024 14:34:49 +0800 Subject: [PATCH] refactor: polish the usage of `z_result_t` in for loop --- examples/z_get.c | 4 ++-- examples/z_get_liveliness.c | 2 +- examples/z_get_shm.c | 4 ++-- examples/z_non_blocking_get.c | 7 ++++--- examples/z_queryable_with_channels.c | 2 +- tests/z_int_queryable_attachment_test.c | 2 +- tests/z_int_queryable_test.c | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/z_get.c b/examples/z_get.c index a97dd5c1f..d6e6c3552 100644 --- a/examples/z_get.c +++ b/examples/z_get.c @@ -71,7 +71,7 @@ int main(int argc, char **argv) { z_move(opts)); // here, the send is moved and will be dropped by zenoh when adequate z_owned_reply_t reply; - for (z_result_t res = z_recv(z_loan(handler), &reply); res == Z_OK; res = z_recv(z_loan(handler), &reply)) { + while (z_recv(z_loan(handler), &reply) == Z_OK) { if (z_reply_is_ok(z_loan(reply))) { const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply)); @@ -93,4 +93,4 @@ int main(int argc, char **argv) { z_drop(z_move(handler)); z_close(z_move(s)); return 0; -} \ No newline at end of file +} diff --git a/examples/z_get_liveliness.c b/examples/z_get_liveliness.c index d7b0b6737..a0d3ae8b7 100644 --- a/examples/z_get_liveliness.c +++ b/examples/z_get_liveliness.c @@ -53,7 +53,7 @@ int main(int argc, char **argv) { z_fifo_channel_reply_new(&closure, &handler, 16); zc_liveliness_get(z_loan(s), z_loan(keyexpr), z_move(closure), NULL); z_owned_reply_t reply; - for (z_result_t res = z_recv(z_loan(handler), &reply); res == Z_OK; res = z_recv(z_loan(handler), &reply)) { + while (z_recv(z_loan(handler), &reply) == Z_OK) { if (z_reply_is_ok(z_loan(reply))) { const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply)); z_view_string_t key_str; diff --git a/examples/z_get_shm.c b/examples/z_get_shm.c index 34d43a5d1..0650eb576 100644 --- a/examples/z_get_shm.c +++ b/examples/z_get_shm.c @@ -109,7 +109,7 @@ int main(int argc, char** argv) { z_move(opts)); // here, the send is moved and will be dropped by zenoh when adequate z_owned_reply_t reply; - for (z_result_t res = z_recv(z_loan(handler), &reply); res == Z_OK; res = z_recv(z_loan(handler), &reply)) { + while (z_recv(z_loan(handler), &reply) == Z_OK) { if (z_reply_is_ok(z_loan(reply))) { const z_loaned_sample_t* sample = z_reply_ok(z_loan(reply)); @@ -135,4 +135,4 @@ int main(int argc, char** argv) { z_drop(z_move(provider)); z_drop(z_move(layout)); return 0; -} \ No newline at end of file +} diff --git a/examples/z_non_blocking_get.c b/examples/z_non_blocking_get.c index cda250aa8..b1bfd88da 100644 --- a/examples/z_non_blocking_get.c +++ b/examples/z_non_blocking_get.c @@ -55,8 +55,9 @@ int main(int argc, char **argv) { z_get(z_loan(s), z_loan(keyexpr), "", z_move(closure), z_move(opts)); // here, the closure is moved and will be dropped by zenoh when adequate z_owned_reply_t reply; - for (z_result_t res = z_try_recv(z_loan(handler), &reply); res != Z_CHANNEL_DISCONNECTED; - res = z_try_recv(z_loan(handler), &reply)) { + + z_result_t res; + while ((res = z_try_recv(z_loan(handler), &reply)) != Z_CHANNEL_DISCONNECTED) { if (res != Z_OK) { z_sleep_ms(50); continue; @@ -78,4 +79,4 @@ int main(int argc, char **argv) { z_drop(z_move(handler)); z_close(z_move(s)); return 0; -} \ No newline at end of file +} diff --git a/examples/z_queryable_with_channels.c b/examples/z_queryable_with_channels.c index a7c1f849e..228ba8c1a 100644 --- a/examples/z_queryable_with_channels.c +++ b/examples/z_queryable_with_channels.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) { printf("^C to quit...\n"); z_owned_query_t oquery; - for (z_result_t res = z_recv(z_loan(handler), &oquery); res == Z_OK; res = z_recv(z_loan(handler), &oquery)) { + while (z_recv(z_loan(handler), &oquery) == Z_OK) { const z_loaned_query_t *query = z_loan(oquery); z_view_string_t key_string; z_keyexpr_as_view_string(z_query_keyexpr(query), &key_string); diff --git a/tests/z_int_queryable_attachment_test.c b/tests/z_int_queryable_attachment_test.c index 55f2681b5..b08ffcb08 100644 --- a/tests/z_int_queryable_attachment_test.c +++ b/tests/z_int_queryable_attachment_test.c @@ -190,7 +190,7 @@ int run_get() { opts.attachment = &attachment; z_get(z_loan(s), z_loan(ke), "", z_move(closure), &opts); z_owned_reply_t reply; - for (z_result_t res = z_recv(z_loan(handler), &reply); res == Z_OK; res = z_recv(z_loan(handler), &reply)) { + while (z_recv(z_loan(handler), &reply) == Z_OK) { assert(z_reply_is_ok(z_loan(reply))); const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply)); diff --git a/tests/z_int_queryable_test.c b/tests/z_int_queryable_test.c index 7446272c8..bf46d00f9 100644 --- a/tests/z_int_queryable_test.c +++ b/tests/z_int_queryable_test.c @@ -109,7 +109,7 @@ int run_get() { z_get_options_default(&opts); z_get(z_loan(s), z_loan(ke), "", z_move(closure), &opts); z_owned_reply_t reply; - for (z_result_t res = z_recv(z_loan(handler), &reply); res == Z_OK; res = z_recv(z_loan(handler), &reply)) { + while (z_recv(z_loan(handler), &reply) == Z_OK) { assert(z_reply_is_ok(z_loan(reply))); const z_loaned_sample_t *sample = z_reply_ok(z_loan(reply));