From 218e072104239f18724055a82ec1f5d04833acc4 Mon Sep 17 00:00:00 2001 From: David Bar-On Date: Wed, 17 Jul 2024 23:22:35 +0300 Subject: [PATCH] Add textual description of the State in the debug messages --- src/iperf_api.c | 9 ++++++++- src/iperf_client_api.c | 2 +- src/iperf_server_api.c | 11 ++++++++++- src/iperf_tcp.c | 3 ++- src/iperf_util.c | 26 ++++++++++++++++++++++++++ src/iperf_util.h | 2 ++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/iperf_api.c b/src/iperf_api.c index 9679a6a12..1ba51cbd2 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1862,7 +1862,8 @@ int iperf_set_send_state(struct iperf_test *test, signed char state) { if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "State change: sending and setting State to %d (control socket is %d)\n", state, test->ctrl_sck); + iperf_printf(test, "State change: sending and setting State to %d - %s (control socket is %d)\n", + state, state_to_text(state), test->ctrl_sck); } if (test->ctrl_sck >= 0) { @@ -4751,6 +4752,9 @@ iperf_got_sigend(struct iperf_test *test) cpu_util(test->cpu_util); test->stats_callback(test); test->state = DISPLAY_RESULTS; /* change local state only */ + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state)); + } if (test->on_test_finish) test->on_test_finish(test); test->reporter_callback(test); @@ -4758,6 +4762,9 @@ iperf_got_sigend(struct iperf_test *test) if (test->ctrl_sck >= 0) { test->state = (test->role == 'c') ? CLIENT_TERMINATE : SERVER_TERMINATE; + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state)); + } (void) Nwrite(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp); } i_errno = (test->role == 'c') ? IECLIENTTERM : IESERVERTERM; diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 4af646834..90d4d4da1 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -300,7 +300,7 @@ iperf_handle_message_client(struct iperf_test *test) } if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "State change: client received State %d\n", test->state); + iperf_printf(test, "State change: client received State %d - %s\n", test->state, state_to_text(test->state)); } switch (test->state) { diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 7df3bd6f0..c03d99377 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -223,6 +223,9 @@ iperf_handle_message_server(struct iperf_test *test) iperf_err(test, "the client has unexpectedly closed the connection"); i_errno = IECTRLCLOSE; test->state = IPERF_DONE; + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state)); + } return 0; } else { i_errno = IERECVMESSAGE; @@ -231,7 +234,7 @@ iperf_handle_message_server(struct iperf_test *test) } if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "State change: server received State %d\n", test->state); + iperf_printf(test, "State change: server received State %d - %s\n", test->state, state_to_text(test->state)); } switch(test->state) { @@ -277,6 +280,9 @@ iperf_handle_message_server(struct iperf_test *test) close(sp->socket); } test->state = IPERF_DONE; + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state)); + } break; default: i_errno = IEMESSAGE; @@ -553,6 +559,9 @@ iperf_run_server(struct iperf_test *test) last_receive_blocks = 0; test->state = IPERF_START; + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "State change: State set to %d - %s\n", test->state, state_to_text(test->state)); + } send_streams_accepted = 0; rec_streams_accepted = 0; rcv_timeout_us = (test->settings->rcv_timeout.secs * SEC_TO_US) + test->settings->rcv_timeout.usecs; diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c index e025515ab..1269e3fb6 100644 --- a/src/iperf_tcp.c +++ b/src/iperf_tcp.c @@ -41,6 +41,7 @@ #include "iperf.h" #include "iperf_api.h" #include "iperf_tcp.h" +#include "iperf_util.h" #include "net.h" #include "cjson.h" @@ -69,7 +70,7 @@ iperf_tcp_recv(struct iperf_stream *sp) } else { if (sp->test->debug) - printf("Late receive, state = %d\n", sp->test->state); + printf("Late receive, state = %d - %s\n", sp->test->state, state_to_text(sp->test->state)); } return r; diff --git a/src/iperf_util.c b/src/iperf_util.c index 81e8da108..4b3846625 100644 --- a/src/iperf_util.c +++ b/src/iperf_util.c @@ -595,3 +595,29 @@ getline(char **buf, size_t *bufsiz, FILE *fp) } #endif + +/* Translate numeric State to text - for debugging pupposes */ +char * +state_to_text(signed char state) +{ + char *txt; + + switch (state) { + case 1: txt = "Starting a Test"; break; + case 2: txt = "Test is Running"; break; + case 4: txt = "Test Ended"; break; + case 9: txt = "Client to Server Parameters Exchange"; break; + case 10: txt = "Creating Streams"; break; + case 11: txt = "Server Terminated"; break; + case 12: txt = "Client Terminated"; break; + case 13: txt = "Exchanging Results"; break; + case 14: txt = "Displaying Results"; break; + case 15: txt = "Starting"; break; + case 16: txt = "Done"; break; + case -1: txt = "Error"; break; + case -2: txt = "Serevr Error"; break; + default: txt = "Unknown State"; + } + + return txt; +} \ No newline at end of file diff --git a/src/iperf_util.h b/src/iperf_util.h index b109af2c6..a371cfcaa 100644 --- a/src/iperf_util.h +++ b/src/iperf_util.h @@ -64,4 +64,6 @@ extern int daemon(int nochdir, int noclose); ssize_t getline(char **buf, size_t *bufsiz, FILE *fp); #endif /* HAVE_GETLINE */ +char * state_to_text(signed char state); + #endif