From 76c60ee7b876b9fb93ba0661ca99b428946ea336 Mon Sep 17 00:00:00 2001 From: DavidBar-On Date: Sat, 8 Feb 2025 10:46:34 +0200 Subject: [PATCH] Per reviewer comment - add parameter to the callback function and enhanced per PR #1805 (with rebase) --- src/iperf.h | 4 ++-- src/iperf_api.c | 6 +++--- src/iperf_api.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/iperf.h b/src/iperf.h index a42e4535d..cb2807a6f 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -343,8 +343,8 @@ struct iperf_test int verbose; /* -V option - verbose mode */ int json_output; /* -J option - JSON output */ int json_stream; /* --json-stream */ - void (*json_callback) (char *); /* used by user apps to receive the JSON strings, - instead of writing them to the output file */ + void (*json_callback) (struct iperf_test *, char *); /* allow user apps to receive the + JSON strings,instead of writing them to the output file */ int zerocopy; /* -Z option - use sendfile */ int debug; /* -d option - enable debug */ enum debug_level debug_level; /* -d option option - level of debug messages to show */ diff --git a/src/iperf_api.c b/src/iperf_api.c index d8be138dc..6fbd79f84 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -698,7 +698,7 @@ iperf_set_test_json_stream(struct iperf_test *ipt, int json_stream) } void -iperf_set_test_json_callback(struct iperf_test *ipt, void (*callback)()) +iperf_set_test_json_callback(struct iperf_test *ipt, void (*callback)(struct iperf_test *, char *)) { ipt->json_callback = callback; } @@ -2871,7 +2871,7 @@ JSONStream_Output(struct iperf_test * test, const char * event_name, cJSON * obj if (str == NULL) return -1; if (test->json_callback != NULL) { - (test->json_callback)(str); + (test->json_callback)(test, str); } else { if (pthread_mutex_lock(&(test->print_mutex)) != 0) { perror("iperf_json_finish: pthread_mutex_lock"); @@ -5048,7 +5048,7 @@ iperf_json_finish(struct iperf_test *test) return -1; } if (test->json_callback != NULL) { - (test->json_callback)(test->json_output_string); + (test->json_callback)(test, test->json_output_string); } else { if (pthread_mutex_lock(&(test->print_mutex)) != 0) { perror("iperf_json_finish: pthread_mutex_lock"); diff --git a/src/iperf_api.h b/src/iperf_api.h index 8d4613d61..471cc9032 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -197,7 +197,7 @@ void iperf_set_test_template( struct iperf_test *ipt, const char *tmp_templat void iperf_set_test_reverse( struct iperf_test* ipt, int reverse ); void iperf_set_test_json_output( struct iperf_test* ipt, int json_output ); void iperf_set_test_json_stream( struct iperf_test* ipt, int json_stream ); -void iperf_set_test_json_callback(struct iperf_test *ipt, void (*callback)()); +void iperf_set_test_json_callback(struct iperf_test *ipt, void (*callback)(struct iperf_test *, char *)); int iperf_has_zerocopy( void ); void iperf_set_test_zerocopy( struct iperf_test* ipt, int zerocopy ); void iperf_set_test_get_server_output( struct iperf_test* ipt, int get_server_output );