diff --git a/configure.ac b/configure.ac index e05db660..eec8c1a5 100644 --- a/configure.ac +++ b/configure.ac @@ -305,33 +305,36 @@ AC_SEARCH_LIBS([dlopen], [dl], [], # ----- Check for pthreads +AX_PTHREAD([ + AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and header files.]) + appendCXX "$PTHREAD_CFLAGS" + appendLib "$PTHREAD_LIBS" +], [ + AC_MSG_ERROR([This compiler/OS doesn't seem to support pthreads.]) +]) + +# Note that old broken systems, such as OpenBSD, NetBSD, which don't support AI_ADDRCONFIG, also have thread-unsafe getaddrinfo(). +# Gladly, they fixed thread-safety before support of AI_ADDRCONFIG, so this can be abused to detect the thread-safe getaddrinfo(). +# +# TODO: drop support of blocking DNS at some point. OpenBSD supports AI_ADDRCONFIG since Nov 2014, and their getaddrinfo() is thread-safe since Nov 2013. NetBSD's one is thread-safe since ages ago. DNS_TEXT=blocking if test "x$TDNS" != "xno"; then old_TDNS=$TDNS - AX_PTHREAD([ - AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and header files.]) - appendCXX "$PTHREAD_CFLAGS" - appendLib "$PTHREAD_LIBS" - AC_MSG_CHECKING([whether getaddrinfo() supports AI_ADDRCONFIG]) - AC_COMPILE_IFELSE([ - AC_LANG_PROGRAM([[ - #include - #include - #include - ]], [[ - int x = AI_ADDRCONFIG; - (void) x; - ]]) - ], [ - AC_MSG_RESULT([yes]) - TDNS=yes - ], [ - AC_MSG_RESULT([no]) - TDNS=no - # Note that broken systems, such as OpenBSD, NetBSD, which don't support AI_ADDRCONFIG, - # also have thread-unsafe getaddrinfo(). - ]) + AC_MSG_CHECKING([whether getaddrinfo() supports AI_ADDRCONFIG]) + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ + #include + #include + #include + ]], [[ + int x = AI_ADDRCONFIG; + (void) x; + ]]) ], [ + AC_MSG_RESULT([yes]) + TDNS=yes + ], [ + AC_MSG_RESULT([no]) TDNS=no ]) if test "x$TDNS" = "xyes"; then diff --git a/include/znc/Socket.h b/include/znc/Socket.h index df091f03..1c82b3a7 100644 --- a/include/znc/Socket.h +++ b/include/znc/Socket.h @@ -135,8 +135,10 @@ public: private: void FinishConnect(const CString& sHostname, u_short iPort, const CString& sSockName, int iTimeout, bool bSSL, const CString& sBindHost, CZNCSock *pcSock); - class CTDNSMonitorFD; - friend class CTDNSMonitorFD; +#ifdef HAVE_PTHREAD + class CThreadMonitorFD; + friend class CThreadMonitorFD; +#endif #ifdef HAVE_THREADED_DNS struct TDNSTask { TDNSTask() : sHostname(""), iPort(0), sSockName(""), iTimeout(0), bSSL(false), sBindhost(""), pcSock(nullptr), bDoneTarget(false), bDoneBind(false), aiTarget(nullptr), aiBind(nullptr) {} diff --git a/src/Socket.cpp b/src/Socket.cpp index 2787caa9..d316bcdc 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -158,9 +158,9 @@ CString CZNCSock::GetSSLPeerFingerprint() const { } #ifdef HAVE_PTHREAD -class CSockManager::CTDNSMonitorFD : public CSMonitorFD { +class CSockManager::CThreadMonitorFD : public CSMonitorFD { public: - CTDNSMonitorFD() { + CThreadMonitorFD() { Add(CThreadPool::Get().getReadFD(), ECT_Read); } @@ -346,7 +346,7 @@ void CSockManager::SetTDNSThreadFinished(TDNSTask* task, bool bBind, addrinfo* a CSockManager::CSockManager() { #ifdef HAVE_PTHREAD - MonitorFD(new CTDNSMonitorFD()); + MonitorFD(new CThreadMonitorFD()); #endif }