From 662a8362c4f2610208135c6adaa82acfb47866a0 Mon Sep 17 00:00:00 2001 From: "Bruce A. Mah" Date: Thu, 12 Jun 2014 11:38:43 -0700 Subject: [PATCH] Fix a bug in the structure of the --json output. The various "connected" structures were just dumped into the "start" structure. This caused problems if there were multiple connections (i.e. multiple parallel streams), because the "connected" structures would overwrite themselves. Instead, make these structures members of a "connected" array. This is technically an incompatible API change, but the prior behavior was unusable. Discovered and fix suggested by: @i2aaron (cherry picked from commit a134ba0a0230b85494e64fb903aafc35b5bfa9d5) Signed-off-by: Bruce A. Mah --- src/iperf.h | 1 + src/iperf_api.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/iperf.h b/src/iperf.h index fc07fc4..fc4c514 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -225,6 +225,7 @@ struct iperf_test /* cJSON handles for use when in -J mode */\ cJSON *json_top; cJSON *json_start; + cJSON *json_connected; cJSON *json_intervals; cJSON *json_end; diff --git a/src/iperf_api.c b/src/iperf_api.c index 07e1560..11d2614 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1503,7 +1503,7 @@ connect_msg(struct iperf_stream *sp) } if (sp->test->json_output) - cJSON_AddItemToObject(sp->test->json_start, "connected", iperf_json_printf("socket: %d local_host: %s local_port: %d remote_host: %s remote_port: %d", (int64_t) sp->socket, ipl, (int64_t) lport, ipr, (int64_t) rport)); + cJSON_AddItemToArray(sp->test->json_connected, iperf_json_printf("socket: %d local_host: %s local_port: %d remote_host: %s remote_port: %d", (int64_t) sp->socket, ipl, (int64_t) lport, ipr, (int64_t) rport)); else iprintf(sp->test, report_connected, sp->socket, ipl, lport, ipr, rport); } @@ -2502,6 +2502,10 @@ iperf_json_start(struct iperf_test *test) if (test->json_start == NULL) return -1; cJSON_AddItemToObject(test->json_top, "start", test->json_start); + test->json_connected = cJSON_CreateArray(); + if (test->json_connected == NULL) + return -1; + cJSON_AddItemToObject(test->json_start, "connected", test->json_connected); test->json_intervals = cJSON_CreateArray(); if (test->json_intervals == NULL) return -1; @@ -2533,7 +2537,7 @@ iperf_json_finish(struct iperf_test *test) fflush(stdout); free(str); cJSON_Delete(test->json_top); - test->json_top = test->json_start = test->json_intervals = test->json_server_output = test->json_end = NULL; + test->json_top = test->json_start = test->json_connected = test->json_intervals = test->json_server_output = test->json_end = NULL; return 0; }