From 0e6c921b206259474b1c14bb26b183a8b2089cdb Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 12 Sep 2025 08:25:16 +0200 Subject: [PATCH 1/2] [winpr,threadpool] default minimum thread count Set a default minimum of 4 threads in a pool. Avoids issues with system running with a single processor (might lead to deadlocks if the code assumes > 1 thread handling stuff) --- winpr/libwinpr/pool/CMakeLists.txt | 2 ++ winpr/libwinpr/pool/pool.c | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/winpr/libwinpr/pool/CMakeLists.txt b/winpr/libwinpr/pool/CMakeLists.txt index cfa9bc891..6b5938fd0 100644 --- a/winpr/libwinpr/pool/CMakeLists.txt +++ b/winpr/libwinpr/pool/CMakeLists.txt @@ -16,7 +16,9 @@ # limitations under the License. set(WINPR_THREADPOOL_DEFAULT_MAX_COUNT "16" CACHE STRING "The maximum (default) number of threads in a pool") +set(WINPR_THREADPOOL_DEFAULT_MIN_COUNT "4" CACHE STRING "The minimum (default) number of threads in a pool") winpr_definition_add(WINPR_THREADPOOL_DEFAULT_MAX_COUNT=${WINPR_THREADPOOL_DEFAULT_MAX_COUNT}) +winpr_definition_add(WINPR_THREADPOOL_DEFAULT_MIN_COUNT=${WINPR_THREADPOOL_DEFAULT_MIN_COUNT}) winpr_module_add( synch.c work.c diff --git a/winpr/libwinpr/pool/pool.c b/winpr/libwinpr/pool/pool.c index 96db6b247..cbfc274c5 100644 --- a/winpr/libwinpr/pool/pool.c +++ b/winpr/libwinpr/pool/pool.c @@ -127,10 +127,15 @@ static BOOL InitializeThreadpool(PTP_POOL pool) obj = ArrayList_Object(pool->Threads); obj->fnObjectFree = threads_close; +#if !defined(WINPR_THREADPOOL_DEFAULT_MIN_COUNT) +#error "WINPR_THREADPOOL_DEFAULT_MIN_COUNT must be defined" +#endif + SYSTEM_INFO info = { 0 }; GetSystemInfo(&info); - if (info.dwNumberOfProcessors < 1) - info.dwNumberOfProcessors = 1; + if (info.dwNumberOfProcessors < WINPR_THREADPOOL_DEFAULT_MIN_COUNT) + info.dwNumberOfProcessors = WINPR_THREADPOOL_DEFAULT_MIN_COUNT; + if (!SetThreadpoolThreadMinimum(pool, info.dwNumberOfProcessors)) goto fail; From bc682c33326ad4f45c14bd8a2637a53f1fd4d1db Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 12 Sep 2025 08:37:58 +0200 Subject: [PATCH 2/2] [core,peer] only set TCP_NODELAY on SOCK_STREAM sockets --- libfreerdp/core/peer.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index 4c4f88100..1b9ca700b 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -1455,11 +1455,31 @@ freerdp_peer* freerdp_peer_new(int sockfd) if (sockfd >= 0) { - if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*)&option_value, option_len) < 0) + int type = -1; + socklen_t typelen = sizeof(type); + const int rc = getsockopt(sockfd, SOL_SOCKET, SO_TYPE, &type, &typelen); + if (rc < 0) { - /* local unix sockets don't have the TCP_NODELAY implemented, so don't make this - * error fatal */ - WLog_DBG(TAG, "can't set TCP_NODELAY, continuing anyway"); + char buffer[128] = { 0 }; + WLog_DBG(TAG, "can't get SOL_SOCKET|SO_TYPE, continuing anyway (%s)", + winpr_strerror(errno, buffer, sizeof(buffer))); + } + else if (type == SOCK_STREAM) + { + const int sr = + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (void*)&option_value, option_len); + if (sr < 0) + { + /* local unix sockets don't have the TCP_NODELAY implemented, so don't make this + * error fatal */ + char buffer[128] = { 0 }; + WLog_DBG(TAG, "can't set TCP_NODELAY, continuing anyway (%s)", + winpr_strerror(errno, buffer, sizeof(buffer))); + } + } + else + { + WLog_DBG(TAG, "Socket SOL_SOCKET|SO_TYPE %d unsupported, continuing anyway", type); } }