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
This commit is contained in:
Bruce A. Mah 2014-06-12 11:38:43 -07:00
parent 487ee8102f
commit a134ba0a02
No known key found for this signature in database
GPG Key ID: 4984910A8CAAEE8A
2 changed files with 7 additions and 2 deletions

View File

@ -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;

View File

@ -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;
}