diff --git a/src/iperf_api.c b/src/iperf_api.c index c540beb..163c779 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -2317,14 +2317,27 @@ iperf_catch_sigend(void (*handler)(int)) void iperf_got_sigend(struct iperf_test *test) { + /* + * If we're the client, or if we're a server and running a test, + * then dump out the accumulated stats so far. + */ + if (test->role == 'c' || + (test->role == 's' && test->state == TEST_RUNNING)) { + + test->done = 1; + cpu_util(test->cpu_util); + test->stats_callback(test); + test->state = DISPLAY_RESULTS; /* change local state only */ + if (test->on_test_finish) + test->on_test_finish(test); + test->reporter_callback(test); + } + if (test->ctrl_sck >= 0) { test->state = (test->role == 'c') ? CLIENT_TERMINATE : SERVER_TERMINATE; (void) Nwrite(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp); } i_errno = (test->role == 'c') ? IECLIENTTERM : IESERVERTERM; - /* If the client, then dump JSON output if any */ - if (test->role == 'c') - iperf_client_end(test); iperf_errexit(test, "interrupt - %s", iperf_strerror(i_errno)); } diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index f2e2a4e..8846247 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -221,6 +221,16 @@ iperf_handle_message_client(struct iperf_test *test) break; case SERVER_TERMINATE: i_errno = IESERVERTERM; + + /* + * Temporarily be in DISPLAY_RESULTS phase so we can get + * ending summary statistics. + */ + signed char oldstate = test->state; + cpu_util(test->cpu_util); + test->state = DISPLAY_RESULTS; + test->reporter_callback(test); + test->state = oldstate; return -1; case ACCESS_DENIED: i_errno = IEACCESSDENIED; diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 659502f..f490fc4 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2011, The Regents of the University of California, + * Copyright (c) 2009-2014, 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. * @@ -204,6 +204,14 @@ iperf_handle_message_server(struct iperf_test *test) case CLIENT_TERMINATE: i_errno = IECLIENTTERM; + // Temporarily be in DISPLAY_RESULTS phase so we can get + // ending summary statistics. + signed char oldstate = test->state; + cpu_util(test->cpu_util); + test->state = DISPLAY_RESULTS; + test->reporter_callback(test); + test->state = oldstate; + // XXX: Remove this line below! iperf_err(test, "the client has terminated"); SLIST_FOREACH(sp, &test->streams, streams) {