From 82c17ea813b5a89401d56305e5c5946299de74a4 Mon Sep 17 00:00:00 2001 From: Eric Eichhorn Date: Tue, 22 Oct 2024 12:36:03 +0200 Subject: [PATCH] fix: aix build #4742 --- Foundation/CMakeLists.txt | 9 ++++++++- Foundation/include/Poco/Thread_POSIX.h | 2 ++ Foundation/src/Thread_POSIX.cpp | 8 ++++++++ Foundation/testsuite/src/ThreadTest.cpp | 12 ++++++++++++ Net/src/SocketImpl.cpp | 12 ++++++++++-- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Foundation/CMakeLists.txt b/Foundation/CMakeLists.txt index 8e0d9e8598..942f98700a 100644 --- a/Foundation/CMakeLists.txt +++ b/Foundation/CMakeLists.txt @@ -160,8 +160,10 @@ else() target_compile_definitions(Foundation PUBLIC POCO_HAVE_FD_POLL) target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "GNU") + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) target_compile_definitions(Foundation PUBLIC _XOPEN_SOURCE=500 POCO_HAVE_FD_POLL) - target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt) + target_link_libraries(Foundation PUBLIC ${CMAKE_DL_LIBS} rt Threads::Threads) else() target_compile_definitions(Foundation PUBLIC _XOPEN_SOURCE=500 POCO_HAVE_FD_EPOLL) target_link_libraries(Foundation PUBLIC pthread atomic ${CMAKE_DL_LIBS} rt) @@ -206,6 +208,11 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro") target_compile_options(Foundation PUBLIC -library=stlport4) endif() +# AIX +if("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX") + target_compile_definitions(Foundation PUBLIC POCO_NO_THREADNAME) +endif() + # iOS if(IOS) target_compile_definitions(Foundation diff --git a/Foundation/include/Poco/Thread_POSIX.h b/Foundation/include/Poco/Thread_POSIX.h index 5f64ac2ed1..1ae01a656c 100644 --- a/Foundation/include/Poco/Thread_POSIX.h +++ b/Foundation/include/Poco/Thread_POSIX.h @@ -64,10 +64,12 @@ class Foundation_API ThreadImpl TIDImpl tidImpl() const; void setNameImpl(const std::string& threadName); std::string getNameImpl() const; +#ifndef POCO_NO_THREADNAME std::string getOSThreadNameImpl(); /// Returns the thread's name, expressed as an operating system /// specific name value. Return empty string if thread is not running. /// For test used only. +#endif void setPriorityImpl(int prio); int getPriorityImpl() const; void setOSPriorityImpl(int prio, int policy = SCHED_OTHER); diff --git a/Foundation/src/Thread_POSIX.cpp b/Foundation/src/Thread_POSIX.cpp index 89313b15cf..20232f9eab 100644 --- a/Foundation/src/Thread_POSIX.cpp +++ b/Foundation/src/Thread_POSIX.cpp @@ -91,6 +91,7 @@ namespace return name; } +#ifndef POCO_NO_THREADNAME void setThreadName(const std::string& threadName) /// Sets thread name. Support for this feature varies /// on platforms. Any errors are ignored. @@ -134,6 +135,7 @@ namespace #endif return name; } +#endif } @@ -191,10 +193,12 @@ std::string ThreadImpl::getNameImpl() const } +#ifndef POCO_NO_THREADNAME std::string ThreadImpl::getOSThreadNameImpl() { return isRunningImpl() ? getThreadName() : ""; } +#endif void ThreadImpl::setPriorityImpl(int prio) @@ -430,13 +434,17 @@ void* ThreadImpl::runnableEntry(void* pThread) #endif ThreadImpl* pThreadImpl = reinterpret_cast(pThread); +#ifndef POCO_NO_THREADNAME setThreadName(reinterpret_cast(pThread)->getName()); +#endif AutoPtr pData = pThreadImpl->_pData; +#ifndef POCO_NO_THREADNAME { FastMutex::ScopedLock lock(pData->mutex); setThreadName(pData->name); } +#endif try { diff --git a/Foundation/testsuite/src/ThreadTest.cpp b/Foundation/testsuite/src/ThreadTest.cpp index fe3006ae22..6a7f0ea4ef 100644 --- a/Foundation/testsuite/src/ThreadTest.cpp +++ b/Foundation/testsuite/src/ThreadTest.cpp @@ -43,8 +43,10 @@ class MyRunnable: public Runnable if (pThread) { _threadName = pThread->name(); +#ifndef POCO_NO_THREADNAME auto *pThreadImpl = reinterpret_cast(pThread); _osThreadName = pThreadImpl->getOSThreadNameImpl(); +#endif } _ran = true; _event.wait(); @@ -60,10 +62,12 @@ class MyRunnable: public Runnable return _threadName; } +#ifndef POCO_NO_THREADNAME const std::string& osThreadName() const { return _osThreadName; } +#endif void notify() { @@ -80,7 +84,9 @@ class MyRunnable: public Runnable private: bool _ran; std::string _threadName; +#ifndef POCO_NO_THREADNAME std::string _osThreadName; +#endif Event _event; }; @@ -209,7 +215,9 @@ void ThreadTest::testThread() assertTrue (!thread.isRunning()); assertTrue (r.ran()); assertTrue (!r.threadName().empty()); +#ifndef POCO_NO_THREADNAME assertTrue (!r.osThreadName().empty()); +#endif } @@ -222,7 +230,9 @@ void ThreadTest::testNamedThread() thread.join(); assertTrue (r.ran()); assertTrue (r.threadName() == "MyThread"); +#ifndef POCO_NO_THREADNAME assertTrue (r.osThreadName() == r.threadName()); +#endif // name len > POCO_MAX_THREAD_NAME_LEN Thread thread2("0123456789aaaaaaaaaa9876543210"); @@ -231,7 +241,9 @@ void ThreadTest::testNamedThread() r2.notify(); thread2.join(); assertTrue (r2.ran()); +#ifndef POCO_NO_THREADNAME assertTrue (r2.osThreadName() == r2.threadName()); +#endif assertTrue (r2.threadName().length() <= POCO_MAX_THREAD_NAME_LEN); assertTrue (std::string(r2.threadName(), 0, 7) == "0123456"); assertTrue (std::string(r2.threadName(), r2.threadName().size() - 7) == "6543210"); diff --git a/Net/src/SocketImpl.cpp b/Net/src/SocketImpl.cpp index 5a3c7b1197..deaf92f1ac 100644 --- a/Net/src/SocketImpl.cpp +++ b/Net/src/SocketImpl.cpp @@ -1440,7 +1440,11 @@ Int64 SocketImpl::sendFile(FileInputStream &fileInputStream, UInt64 offset) UInt64 fileSize = fileInputStream.size(); std::streamoff sentSize = fileSize - offset; Int64 sent = 0; - sighandler_t sigPrev = signal(SIGPIPE, SIG_IGN); + struct sigaction sa, old_sa; + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGPIPE, &sa, &old_sa); while (sent == 0) { errno = 0; @@ -1450,7 +1454,11 @@ Int64 SocketImpl::sendFile(FileInputStream &fileInputStream, UInt64 offset) error(errno, std::string("[sendfile error]") + Error::getMessage(errno)); } } - signal(SIGPIPE, sigPrev != SIG_ERR ? sigPrev : SIG_DFL); + if(old_sa.sa_handler == SIG_ERR) + { + old_sa.sa_handler = SIG_DFL; + } + sigaction(SIGPIPE, &old_sa, nullptr); return sent; } #endif // POCO_OS_FAMILY_WINDOWS