From 0fa598b208182f4a98127193bdd0a36b11c752c6 Mon Sep 17 00:00:00 2001 From: oagniqgnat <2275754866@qq.com> Date: Tue, 17 Feb 2026 17:52:57 +0800 Subject: [PATCH 1/2] Fix iperf3 client hangs --- src/iperf_client_api.c | 2 +- src/iperf_server_api.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 37d741f87..98c32b9e4 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -75,7 +75,7 @@ iperf_client_worker_run(void *s) { } /* Allow this thread to be cancelled even if it's in a syscall */ - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); while (! (test->done) && ! (sp->done)) { diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 8e9b41623..43124e067 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -88,7 +88,7 @@ iperf_server_worker_run(void *s) { } /* Allow this thread to be cancelled even if it's in a syscall */ - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); while (! (test->done) && ! (sp->done)) { From 168e84a952cc67d211d66672ac5357b02a6b5922 Mon Sep 17 00:00:00 2001 From: oagniqgnat <2275754866@qq.com> Date: Tue, 17 Feb 2026 19:58:44 +0800 Subject: [PATCH 2/2] Support android --- src/iperf_pthread.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/iperf_pthread.h b/src/iperf_pthread.h index 9fe3db8a2..021ad3890 100644 --- a/src/iperf_pthread.h +++ b/src/iperf_pthread.h @@ -9,8 +9,20 @@ /* Adding missing `pthread` related definitions in Android. */ -#define PTHREAD_CANCEL_ASYNCHRONOUS 0 -#define PTHREAD_CANCEL_ENABLE 0 + enum + { + PTHREAD_CANCEL_ENABLE, + #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE + PTHREAD_CANCEL_DISABLE + #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE + }; + enum + { + PTHREAD_CANCEL_DEFERRED, + #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED + PTHREAD_CANCEL_ASYNCHRONOUS + #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS + }; int pthread_setcanceltype(int type, int *oldtype); int pthread_setcancelstate(int state, int *oldstate);