@@ -704,16 +704,23 @@ iperf_run_client(struct iperf_test * test)
704
704
(test -> settings -> blocks != 0 && (test -> blocks_sent >= test -> settings -> blocks ||
705
705
test -> blocks_received >= test -> settings -> blocks )))) {
706
706
707
- /* Cancel sender threads */
707
+ /* Cancel outstanding sender threads */
708
708
SLIST_FOREACH (sp , & test -> streams , streams ) {
709
709
if (sp -> sender ) {
710
+ int rc ;
710
711
sp -> done = 1 ;
711
- if (pthread_cancel (sp -> thr ) != 0 ) {
712
+ rc = pthread_cancel (sp -> thr );
713
+ if (rc != 0 && rc != ESRCH ) {
712
714
i_errno = IEPTHREADCANCEL ;
715
+ errno = rc ;
716
+ iperf_err (test , "sender cancel in pthread_cancel - %s" , iperf_strerror (i_errno ));
713
717
goto cleanup_and_fail ;
714
718
}
715
- if (pthread_join (sp -> thr , NULL ) != 0 ) {
719
+ rc = pthread_join (sp -> thr , NULL );
720
+ if (rc != 0 && rc != ESRCH ) {
716
721
i_errno = IEPTHREADJOIN ;
722
+ errno = rc ;
723
+ iperf_err (test , "sender cancel in pthread_join - %s" , iperf_strerror (i_errno ));
717
724
goto cleanup_and_fail ;
718
725
}
719
726
if (test -> debug_level >= DEBUG_LEVEL_INFO ) {
@@ -735,16 +742,23 @@ iperf_run_client(struct iperf_test * test)
735
742
}
736
743
}
737
744
738
- /* Cancel receiver threads */
745
+ /* Cancel outstanding receiver threads */
739
746
SLIST_FOREACH (sp , & test -> streams , streams ) {
740
747
if (!sp -> sender ) {
748
+ int rc ;
741
749
sp -> done = 1 ;
742
- if (pthread_cancel (sp -> thr ) != 0 ) {
750
+ rc = pthread_cancel (sp -> thr );
751
+ if (rc != 0 && rc != ESRCH ) {
743
752
i_errno = IEPTHREADCANCEL ;
753
+ errno = rc ;
754
+ iperf_err (test , "receiver cancel in pthread_cancel - %s" , iperf_strerror (i_errno ));
744
755
goto cleanup_and_fail ;
745
756
}
746
- if (pthread_join (sp -> thr , NULL ) != 0 ) {
757
+ rc = pthread_join (sp -> thr , NULL );
758
+ if (rc != 0 && rc != ESRCH ) {
747
759
i_errno = IEPTHREADJOIN ;
760
+ errno = rc ;
761
+ iperf_err (test , "receiver cancel in pthread_join - %s" , iperf_strerror (i_errno ));
748
762
goto cleanup_and_fail ;
749
763
}
750
764
if (test -> debug_level >= DEBUG_LEVEL_INFO ) {
@@ -769,17 +783,22 @@ iperf_run_client(struct iperf_test * test)
769
783
return 0 ;
770
784
771
785
cleanup_and_fail :
772
- /* Cancel all threads */
786
+ /* Cancel all outstanding threads */
773
787
i_errno_save = i_errno ;
774
788
SLIST_FOREACH (sp , & test -> streams , streams ) {
775
789
sp -> done = 1 ;
776
- if (pthread_cancel (sp -> thr ) != 0 ) {
790
+ int rc ;
791
+ rc = pthread_cancel (sp -> thr );
792
+ if (rc != 0 && rc != ESRCH ) {
777
793
i_errno = IEPTHREADCANCEL ;
778
- iperf_err (test , "cleanup_and_fail in cancel - %s" , iperf_strerror (i_errno ));
794
+ errno = rc ;
795
+ iperf_err (test , "cleanup_and_fail in pthread_cancel - %s" , iperf_strerror (i_errno ));
779
796
}
780
- if (pthread_join (sp -> thr , NULL ) != 0 ) {
797
+ rc = pthread_join (sp -> thr , NULL );
798
+ if (rc != 0 && rc != ESRCH ) {
781
799
i_errno = IEPTHREADJOIN ;
782
- iperf_err (test , "cleanup_and_fail in join - %s" , iperf_strerror (i_errno ));
800
+ errno = rc ;
801
+ iperf_err (test , "cleanup_and_fail in pthread_join - %s" , iperf_strerror (i_errno ));
783
802
}
784
803
if (test -> debug >= DEBUG_LEVEL_INFO ) {
785
804
iperf_printf (test , "Thread FD %d stopped\n" , sp -> socket );
0 commit comments