diff --git a/src/iperf_api.c b/src/iperf_api.c index 7fb741e77..35647f77b 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -4457,6 +4457,7 @@ iperf_new_stream(struct iperf_test *test, int s, int sender) return NULL; } sp->pending_size = 0; + sp->thread_number = 0; /* Set socket */ sp->socket = s; diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 7af54f7aa..a498abc78 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -742,22 +742,28 @@ iperf_run_client(struct iperf_test * test) if (sp->sender) { int rc; sp->done = 1; - rc = pthread_cancel(sp->thr); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADCANCEL; - errno = rc; - iperf_err(test, "sender cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - goto cleanup_and_fail; - } - rc = pthread_join(sp->thr, NULL); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADJOIN; - errno = rc; - iperf_err(test, "sender cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - goto cleanup_and_fail; - } - if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + if (sp->thread_number > 0) { // if thread was created + rc = pthread_cancel(sp->thr); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADCANCEL; + errno = rc; + iperf_err(test, "sender cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + goto cleanup_and_fail; + } + rc = pthread_join(sp->thr, NULL); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADJOIN; + errno = rc; + iperf_err(test, "sender cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + goto cleanup_and_fail; + } + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + } + sp->thread_number = 0; + } else { + if (test->debug_level >= DEBUG_LEVEL_INFO) + iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket); } } } @@ -788,22 +794,28 @@ iperf_run_client(struct iperf_test * test) if (!sp->sender) { int rc; sp->done = 1; - rc = pthread_cancel(sp->thr); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADCANCEL; - errno = rc; - iperf_err(test, "receiver cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - goto cleanup_and_fail; - } - rc = pthread_join(sp->thr, NULL); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADJOIN; - errno = rc; - iperf_err(test, "receiver cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - goto cleanup_and_fail; - } - if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + if (sp->thread_number > 0) { // if thread was created + rc = pthread_cancel(sp->thr); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADCANCEL; + errno = rc; + iperf_err(test, "receiver cancel in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + goto cleanup_and_fail; + } + rc = pthread_join(sp->thr, NULL); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADJOIN; + errno = rc; + iperf_err(test, "receiver cancel in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + goto cleanup_and_fail; + } + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + } + sp->thread_number = 0; + } else { + if (test->debug_level >= DEBUG_LEVEL_INFO) + iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket); } } } @@ -829,20 +841,26 @@ iperf_run_client(struct iperf_test * test) SLIST_FOREACH(sp, &test->streams, streams) { sp->done = 1; int rc; - rc = pthread_cancel(sp->thr); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADCANCEL; - errno = rc; - iperf_err(test, "cleanup_and_fail in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - } - rc = pthread_join(sp->thr, NULL); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADJOIN; - errno = rc; - iperf_err(test, "cleanup_and_fail in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - } - if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + if (sp->thread_number > 0) { // if thread was created + rc = pthread_cancel(sp->thr); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADCANCEL; + errno = rc; + iperf_err(test, "cleanup_and_fail in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + } + rc = pthread_join(sp->thr, NULL); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADJOIN; + errno = rc; + iperf_err(test, "cleanup_and_fail in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + } + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + } + sp->thread_number = 0; + } else { + if (test->debug_level >= DEBUG_LEVEL_INFO) + iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket); } } if (test->debug_level >= DEBUG_LEVEL_INFO) { diff --git a/src/iperf_sctp.c b/src/iperf_sctp.c index 104083281..e36d49d89 100644 --- a/src/iperf_sctp.c +++ b/src/iperf_sctp.c @@ -70,7 +70,7 @@ iperf_sctp_recv(struct iperf_stream *sp) sp->result->bytes_received_this_interval += r; } else { - if (sp->test->debug) + if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG) printf("Late receive, state = %d\n", sp->test->state); } diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index d29f85ead..cb7e328b3 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -428,20 +428,26 @@ cleanup_server(struct iperf_test *test) SLIST_FOREACH(sp, &test->streams, streams) { int rc; sp->done = 1; - rc = pthread_cancel(sp->thr); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADCANCEL; - errno = rc; - iperf_err(test, "cleanup_server in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - } - rc = pthread_join(sp->thr, NULL); - if (rc != 0 && rc != ESRCH) { - i_errno = IEPTHREADJOIN; - errno = rc; - iperf_err(test, "cleanup_server in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); - } - if (test->debug_level >= DEBUG_LEVEL_INFO) { - iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + if (sp->thread_number > 0) { // if thread was created + rc = pthread_cancel(sp->thr); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADCANCEL; + errno = rc; + iperf_err(test, "cleanup_server in pthread_cancel of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + } + rc = pthread_join(sp->thr, NULL); + if (rc != 0 && rc != ESRCH) { + i_errno = IEPTHREADJOIN; + errno = rc; + iperf_err(test, "cleanup_server in pthread_join of thread %d - %s", sp->thread_number, iperf_strerror(i_errno)); + } + if (test->debug_level >= DEBUG_LEVEL_INFO) { + iperf_printf(test, "Thread number %d FD %d stopped\n", sp->thread_number, sp->socket); + } + sp->thread_number = 0; + } else { + if (test->debug_level >= DEBUG_LEVEL_INFO) + iperf_printf(test, "Not stopping thread for FD %d as it was not created\n", sp->socket); } } i_errno = i_errno_save; diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c index 71c40a6ea..877635d99 100644 --- a/src/iperf_tcp.c +++ b/src/iperf_tcp.c @@ -68,7 +68,7 @@ iperf_tcp_recv(struct iperf_stream *sp) sp->result->bytes_received_this_interval += r; } else { - if (sp->test->debug) + if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG) printf("Late receive, state = %d\n", sp->test->state); } diff --git a/src/iperf_udp.c b/src/iperf_udp.c index a603236df..825eae9fe 100644 --- a/src/iperf_udp.c +++ b/src/iperf_udp.c @@ -183,7 +183,7 @@ iperf_udp_recv(struct iperf_stream *sp) sp->jitter += (d - sp->jitter) / 16.0; } else { - if (sp->test->debug) + if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG) printf("Late receive, state = %d\n", sp->test->state); }