From dbd3439cf975e7133b9a19fc3cd89463d6533d1c Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Mon, 28 Oct 2019 13:10:15 +0200 Subject: [PATCH] samples: net: echo_client: Add Kconfig option to run a number of times Add Kconfig option NET_SAMPLE_SEND_ITERATIONS that sets the number of times the Zephyr echo client sample sends its data. By default the value is zero, which means indefinite, and demonstrates the same behavior as before. Signed-off-by: Patrik Flykt --- samples/net/sockets/echo_client/Kconfig | 7 +++++++ samples/net/sockets/echo_client/src/echo-client.c | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/samples/net/sockets/echo_client/Kconfig b/samples/net/sockets/echo_client/Kconfig index 01d423fb250..851189b1454 100644 --- a/samples/net/sockets/echo_client/Kconfig +++ b/samples/net/sockets/echo_client/Kconfig @@ -51,4 +51,11 @@ config NET_SAMPLE_PSK_HEADER_FILE Name of a header file containing a pre-shared key. +config NET_SAMPLE_SEND_ITERATIONS + int "Send sample data this many times" + default 0 + help + Send sample data this many times before exiting. A value of + zero means that the sample application is run forever. + source "Kconfig.zephyr" diff --git a/samples/net/sockets/echo_client/src/echo-client.c b/samples/net/sockets/echo_client/src/echo-client.c index 11aec6999ed..02042a89d5a 100644 --- a/samples/net/sockets/echo_client/src/echo-client.c +++ b/samples/net/sockets/echo_client/src/echo-client.c @@ -257,7 +257,8 @@ static void init_app(void) void main(void) { - int ret; + int ret = 0, i = 0; + int iterations = CONFIG_NET_SAMPLE_SEND_ITERATIONS; init_app(); @@ -269,7 +270,7 @@ void main(void) k_sem_give(&run_app); } - while (true) { + while (iterations == 0 || i < iterations) { /* Wait for the connection. */ k_sem_take(&run_app, K_FOREVER); @@ -277,8 +278,18 @@ void main(void) while (connected && (ret == 0)) { ret = run_udp_and_tcp(); + + if (iterations > 0) { + i++; + if (i >= iterations) { + break; + + } + } } stop_udp_and_tcp(); } + + exit(ret); }