From a134ba0a0230b85494e64fb903aafc35b5bfa9d5 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 --- 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 9d7eb18..ddfe808 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -243,6 +243,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 cc1f9bd..956d360 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1576,7 +1576,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); } @@ -2683,6 +2683,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; @@ -2710,7 +2714,7 @@ iperf_json_finish(struct iperf_test *test) fprintf(test->outfile, "%s\n", test->json_output_string); iflush(test); 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; }