From ac88ce2fdbefd51c436edf5efa22c315374f282f Mon Sep 17 00:00:00 2001 From: Andrew Klofas Date: Mon, 1 Jun 2026 15:08:11 -0700 Subject: [PATCH 1/3] Fix int32_t-vs-int portability; align CThread assignment with std::thread On targets where int32_t is a distinct type from int (e.g. the newlib arm-none-eabi bare-metal toolchain, where int32_t is long int): - CSrtConfig::iMSS is now int32_t, matching the wire field CHandShake::m_iMSS it is clamped against, so the std::min in acceptAndRespond() deduces its template argument. The two SRTO_UDP_SNDBUF/RCVBUF setters that std::max against iMSS read the option value as int32_t for the same reason. - EventVariant grows a no-argument constructor (type = UNDEFINED) for events that pass no argument; TEV_SYNC uses it instead of the ambiguous EventVariant(0) (int32_t vs const CPacket* overloads). - CThread::operator= on the POSIX backend now matches std::thread semantics: assigning to a joinable thread is std::terminate(), not pthread_cancel(). This removes the only pthread_cancel() call, so pthread backends without thread cancellation (Android, OHOS, RTOS pthread layers such as FreeRTOS-Plus-POSIX) need no special-casing. No-ops on platforms where int32_t == int, except the assign-to-joinable IPE path, which now aborts like the ENABLE_STDCXX_SYNC backend instead of cancelling the live thread. --- srtcore/common.h | 7 +++++++ srtcore/core.h | 2 +- srtcore/socketconfig.cpp | 4 ++-- srtcore/socketconfig.h | 2 +- srtcore/sync_posix.cpp | 20 +++++--------------- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/srtcore/common.h b/srtcore/common.h index 5a53c05e6..9d597d125 100644 --- a/srtcore/common.h +++ b/srtcore/common.h @@ -357,6 +357,13 @@ struct EventVariant // Note: UNDEFINED and ARRAY don't have assignment operator. // For ARRAY you'll use 'set' function. For UNDEFINED there's nothing. + // For events that pass no argument (e.g. TEV_SYNC). + EventVariant() + { + type = UNDEFINED; + u.packet = NULL; + } + explicit EventVariant(const srt::CPacket* arg) { type = PACKET; diff --git a/srtcore/core.h b/srtcore/core.h index a4a9acaee..e548c2982 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -929,7 +929,7 @@ class CUDT return; m_pSndBuffer->setRateEstimator(rate); - updateCC(TEV_SYNC, EventVariant(0)); + updateCC(TEV_SYNC, EventVariant()); } diff --git a/srtcore/socketconfig.cpp b/srtcore/socketconfig.cpp index e3ad5cde2..fe2bc9b19 100644 --- a/srtcore/socketconfig.cpp +++ b/srtcore/socketconfig.cpp @@ -161,7 +161,7 @@ struct CSrtConfigSetter { static void set(CSrtConfig& co, const void* optval, int optlen) { - co.iUDPSndBufSize = std::max(co.iMSS, cast_optval(optval, optlen)); + co.iUDPSndBufSize = std::max(co.iMSS, cast_optval(optval, optlen)); } }; @@ -170,7 +170,7 @@ struct CSrtConfigSetter { static void set(CSrtConfig& co, const void* optval, int optlen) { - co.iUDPRcvBufSize = std::max(co.iMSS, cast_optval(optval, optlen)); + co.iUDPRcvBufSize = std::max(co.iMSS, cast_optval(optval, optlen)); } }; template<> diff --git a/srtcore/socketconfig.h b/srtcore/socketconfig.h index f44e3c24c..9abbc0e50 100644 --- a/srtcore/socketconfig.h +++ b/srtcore/socketconfig.h @@ -218,7 +218,7 @@ struct CSrtConfig: CSrtMuxerConfig static const size_t MAX_PFILTER_LENGTH = 64; static const size_t MAX_CONG_LENGTH = 16; - int iMSS; // Maximum Segment Size, in bytes + int32_t iMSS; // Maximum Segment Size, in bytes (int32_t: matches CHandShake::m_iMSS) size_t zExpPayloadSize; // Expected average payload size (user option) // Options diff --git a/srtcore/sync_posix.cpp b/srtcore/sync_posix.cpp index cfbd2ab6d..8c9328ede 100644 --- a/srtcore/sync_posix.cpp +++ b/srtcore/sync_posix.cpp @@ -9,6 +9,7 @@ */ #include "platform_sys.h" +#include #include #include #include @@ -394,22 +395,11 @@ srt::sync::CThread& srt::sync::CThread::operator=(CThread& other) { if (joinable()) { - // If the thread has already terminated, then - // pthread_join() returns immediately. - // But we have to check it has terminated before replacing it. + // Match std::thread semantics: assigning to a joinable thread + // terminates the program ([thread.thread.assign]). This error should + // not normally happen; the log line makes the abort diagnosable. LOGC(inlog.Error, log << "IPE: Assigning to a thread that is not terminated!"); - -#ifndef DEBUG -#if !defined(__ANDROID__) && !defined(__OHOS__) - // In case of production build the hanging thread should be terminated - // to avoid hang ups and align with C++11 implementation. - // There is no pthread_cancel on Android. See #1476. This error should not normally - // happen, but if it happen, then detaching the thread. - pthread_cancel(m_thread); -#endif // __ANDROID__ __OHOS__ -#else - join(); -#endif + std::terminate(); } // Move thread handler from other m_thread = other.m_thread; From 5faa0b18842b748b178b8ef9e0604c45c46594e5 Mon Sep 17 00:00:00 2001 From: Sektor van Skijlen Date: Fri, 12 Jun 2026 08:10:43 +0200 Subject: [PATCH 2/3] Changed zero-filling to the longest field in the union --- srtcore/common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srtcore/common.h b/srtcore/common.h index 9d597d125..52a61b201 100644 --- a/srtcore/common.h +++ b/srtcore/common.h @@ -361,7 +361,8 @@ struct EventVariant EventVariant() { type = UNDEFINED; - u.packet = NULL; + u.ptr = NULL; + u.len = 0; } explicit EventVariant(const srt::CPacket* arg) From 2db582c613335cac9f194fdfba4731930eb69718 Mon Sep 17 00:00:00 2001 From: Sektor van Skijlen Date: Fri, 12 Jun 2026 08:14:35 +0200 Subject: [PATCH 3/3] Fixed build break --- srtcore/common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srtcore/common.h b/srtcore/common.h index 52a61b201..c40d9028e 100644 --- a/srtcore/common.h +++ b/srtcore/common.h @@ -361,8 +361,8 @@ struct EventVariant EventVariant() { type = UNDEFINED; - u.ptr = NULL; - u.len = 0; + u.array.ptr = NULL; + u.array.len = 0; } explicit EventVariant(const srt::CPacket* arg)