Skip to content

Commit

Permalink
Mark times as NULL when canceling times
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Jun 6, 2023
1 parent 04943c3 commit a3df342
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 43 deletions.
48 changes: 24 additions & 24 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3028,14 +3028,7 @@ iperf_free_test(struct iperf_test *test)
free(test->remote_congestion_used);
if (test->timestamp_format)
free(test->timestamp_format);
if (test->omit_timer != NULL)
tmr_cancel(test->omit_timer);
if (test->timer != NULL)
tmr_cancel(test->timer);
if (test->stats_timer != NULL)
tmr_cancel(test->stats_timer);
if (test->reporter_timer != NULL)
tmr_cancel(test->reporter_timer);
iperf_cancel_test_timers(test);

/* Free protocol list */
while (!SLIST_EMPTY(&test->protocols)) {
Expand Down Expand Up @@ -3107,22 +3100,9 @@ iperf_reset_test(struct iperf_test *test)
SLIST_REMOVE_HEAD(&test->streams, streams);
iperf_free_stream(sp);
}
if (test->omit_timer != NULL) {
tmr_cancel(test->omit_timer);
test->omit_timer = NULL;
}
if (test->timer != NULL) {
tmr_cancel(test->timer);
test->timer = NULL;
}
if (test->stats_timer != NULL) {
tmr_cancel(test->stats_timer);
test->stats_timer = NULL;
}
if (test->reporter_timer != NULL) {
tmr_cancel(test->reporter_timer);
test->reporter_timer = NULL;
}

iperf_cancel_test_timers(test);

test->done = 0;

SLIST_INIT(&test->streams);
Expand Down Expand Up @@ -3252,6 +3232,26 @@ iperf_reset_stats(struct iperf_test *test)
}
}

void
iperf_cancel_test_timers(struct iperf_test *test)
{
if (test->stats_timer != NULL) {
tmr_cancel(test->stats_timer);
test->stats_timer = NULL;
}
if (test->reporter_timer != NULL) {
tmr_cancel(test->reporter_timer);
test->reporter_timer = NULL;
}
if (test->omit_timer != NULL) {
tmr_cancel(test->omit_timer);
test->omit_timer = NULL;
}
if (test->timer != NULL) {
tmr_cancel(test->timer);
test->timer = NULL;
}
}

/**************************************************************************/

Expand Down
6 changes: 6 additions & 0 deletions src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ int iperf_defaults(struct iperf_test * testp);
*/
void iperf_free_test(struct iperf_test * testp);

/**
* iperf_cancel_test_timers -- cancel test timers
*
*/
void iperf_cancel_test_timers(struct iperf_test * testp);

/**
* iperf_new_stream -- return a net iperf_stream with default values
*
Expand Down
3 changes: 2 additions & 1 deletion src/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ iperf_run_client(struct iperf_test * test)
test->done = 1;
cpu_util(test->cpu_util);
test->stats_callback(test);
tmr_destroy(); // No need for the timer events at the end of the test
// Timers not needed at test end and may interrupt with select() receive timeout
iperf_cancel_test_timers(test);
if (iperf_set_send_state(test, TEST_END) != 0)
goto cleanup_and_fail;
}
Expand Down
21 changes: 3 additions & 18 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,28 +403,13 @@ cleanup_server(struct iperf_test *test)
close(test->prot_listener);
test->prot_listener = -1;
}

/* Cancel any remaining timers. */
if (test->stats_timer != NULL) {
tmr_cancel(test->stats_timer);
test->stats_timer = NULL;
}
if (test->reporter_timer != NULL) {
tmr_cancel(test->reporter_timer);
test->reporter_timer = NULL;
}
if (test->omit_timer != NULL) {
tmr_cancel(test->omit_timer);
test->omit_timer = NULL;
}

iperf_cancel_test_timers(test); /* Cancel any remaining timers. */

if (test->congestion_used != NULL) {
free(test->congestion_used);
test->congestion_used = NULL;
}
if (test->timer != NULL) {
tmr_cancel(test->timer);
test->timer = NULL;
}
}


Expand Down

0 comments on commit a3df342

Please sign in to comment.