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); } } 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;