Skip to content

Commit

Permalink
fix: aix build #4742
Browse files Browse the repository at this point in the history
  • Loading branch information
Enc-EE authored and matejk committed Oct 23, 2024
1 parent c735162 commit 82c17ea
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Foundation/include/Poco/Thread_POSIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions Foundation/src/Thread_POSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -134,6 +135,7 @@ namespace
#endif
return name;
}
#endif
}


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -430,13 +434,17 @@ void* ThreadImpl::runnableEntry(void* pThread)
#endif

ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
#ifndef POCO_NO_THREADNAME
setThreadName(reinterpret_cast<Thread*>(pThread)->getName());
#endif
AutoPtr<ThreadData> pData = pThreadImpl->_pData;

#ifndef POCO_NO_THREADNAME
{
FastMutex::ScopedLock lock(pData->mutex);
setThreadName(pData->name);
}
#endif

try
{
Expand Down
12 changes: 12 additions & 0 deletions Foundation/testsuite/src/ThreadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class MyRunnable: public Runnable
if (pThread)
{
_threadName = pThread->name();
#ifndef POCO_NO_THREADNAME
auto *pThreadImpl = reinterpret_cast<Poco::ThreadImpl *>(pThread);
_osThreadName = pThreadImpl->getOSThreadNameImpl();
#endif
}
_ran = true;
_event.wait();
Expand All @@ -60,10 +62,12 @@ class MyRunnable: public Runnable
return _threadName;
}

#ifndef POCO_NO_THREADNAME
const std::string& osThreadName() const
{
return _osThreadName;
}
#endif

void notify()
{
Expand All @@ -80,7 +84,9 @@ class MyRunnable: public Runnable
private:
bool _ran;
std::string _threadName;
#ifndef POCO_NO_THREADNAME
std::string _osThreadName;
#endif
Event _event;
};

Expand Down Expand Up @@ -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
}


Expand All @@ -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");
Expand All @@ -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");
Expand Down
12 changes: 10 additions & 2 deletions Net/src/SocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 82c17ea

Please sign in to comment.