Skip to content

Commit

Permalink
Issue 1118 (#1121)
Browse files Browse the repository at this point in the history
* fix: Correctly emit JSON for --server --json.

Put extra error diagnostic information behind --verbose, to avoid putting
extra "error" members in JSON output.

Fixes #1118.
  • Loading branch information
bmah888 authored Feb 8, 2021
1 parent 4108997 commit 25f50c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,8 @@ iperf_check_total_rate(struct iperf_test *test, iperf_size_t last_interval_bytes
}

if (bits_per_second > test->settings->bitrate_limit) {
iperf_err(test, "Total throughput of %" PRIu64 " bps exceeded %" PRIu64 " bps limit", bits_per_second, test->settings->bitrate_limit);
if (iperf_get_verbose(test))
iperf_err(test, "Total throughput of %" PRIu64 " bps exceeded %" PRIu64 " bps limit", bits_per_second, test->settings->bitrate_limit);
test->bitrate_limit_exceeded = 1;
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ iperf_run_server(struct iperf_test *test)
else if (t_usecs > NO_MSG_RCVD_TIMEOUT * SEC_TO_US) {
test->server_forced_no_msg_restarts_count += 1;
i_errno = IENOMSG;
iperf_err(test, "Server restart (#%d) in active test as no message was received for %d sec",
test->server_forced_no_msg_restarts_count, NO_MSG_RCVD_TIMEOUT);
if (iperf_get_verbose(test))
iperf_err(test, "Server restart (#%d) in active test as no message was received for %d sec",
test->server_forced_no_msg_restarts_count, NO_MSG_RCVD_TIMEOUT);
cleanup_server(test);
return -1;
}
Expand Down Expand Up @@ -688,8 +689,9 @@ iperf_run_server(struct iperf_test *test)
/* Ensure that total requested data rate is not above limit */
iperf_size_t total_requested_rate = test->num_streams * test->settings->rate * (test->mode == BIDIRECTIONAL? 2 : 1);
if (test->settings->bitrate_limit > 0 && total_requested_rate > test->settings->bitrate_limit) {
iperf_err(test, "Client total requested throughput rate of %" PRIu64 " bps exceeded %" PRIu64 " bps limit",
total_requested_rate, test->settings->bitrate_limit);
if (iperf_get_verbose(test))
iperf_err(test, "Client total requested throughput rate of %" PRIu64 " bps exceeded %" PRIu64 " bps limit",
total_requested_rate, test->settings->bitrate_limit);
cleanup_server(test);
i_errno = IETOTALRATE;
return -1;
Expand Down
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* iperf, Copyright (c) 2014, 2015, 2017, 2019, The Regents of the University of
* iperf, Copyright (c) 2014-2021, The Regents of the University of
* California, through Lawrence Berkeley National Laboratory (subject
* to receipt of any required approvals from the U.S. Dept. of
* Energy). All rights reserved.
Expand Down Expand Up @@ -154,6 +154,12 @@ run(struct iperf_test *test)
test->server_last_run_rc =rc;
if (rc < 0) {
iperf_err(test, "error - %s", iperf_strerror(i_errno));
if (test->json_output) {
if (iperf_json_finish(test) < 0)
return -1;
}
iflush(test);

if (rc < -1) {
iperf_errexit(test, "exiting");
}
Expand Down

0 comments on commit 25f50c2

Please sign in to comment.