diff --git a/acinclude.m4 b/acinclude.m4 index 8a57a75d..5b397620 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -480,6 +480,17 @@ if test "x$acx_pthread_ok" = xyes; then fi fi + # Detect pthread signal functions + AC_MSG_CHECKING([for pthread signal functions]) + AC_TRY_LINK([#include + #include ], + [pthread_kill(pthread_self(), SIGTERM);], + ok=yes, ok=unknown) + AC_MSG_RESULT(${ok}) + if test x"$ok" != xno; then + AC_DEFINE(HAVE_PTHREAD_SIGNAL,1,[Define if you have \`pthread_sigmask\' and \`pthread_kill\' functions.]) + fi + LIBS="$save_LIBS" CXXFLAGS="$save_CXXFLAGS" diff --git a/configure.in b/configure.in index 6b738b41..2ec6f592 100644 --- a/configure.in +++ b/configure.in @@ -48,7 +48,7 @@ ACX_CHECK_INET_ATON dnl checks for header files AC_HEADER_STDC -AC_CHECK_HEADERS([unistd.h sys/time.h sys/types.h]) +AC_CHECK_HEADERS([unistd.h sys/time.h sys/types.h wchar.h]) AC_CHECK_HEADERS([sys/socket.h sys/select.h]) AC_CHECK_HEADERS([istream ostream sstream]) AC_HEADER_TIME diff --git a/lib/arch/CArchMultithreadPosix.cpp b/lib/arch/CArchMultithreadPosix.cpp index 20a2ad47..8fdd9dde 100644 --- a/lib/arch/CArchMultithreadPosix.cpp +++ b/lib/arch/CArchMultithreadPosix.cpp @@ -30,6 +30,17 @@ #define SIGWAKEUP SIGUSR1 +#if !HAVE_PTHREAD_SIGNAL + // boy, is this platform broken. forget about pthread signal + // handling and let signals through to every process. synergy + // will not terminate cleanly when it gets SIGTERM or SIGINT. +# define pthread_sigmask sigprocmask +# define pthread_kill(tid_, sig_) kill(0, (sig_)) +# define sigwait(set_, sig_) +# undef HAVE_POSIX_SIGWAIT +# define HAVE_POSIX_SIGWAIT 1 +#endif + // // CArchThreadImpl // @@ -318,7 +329,9 @@ CArchMultithreadPosix::newThread(ThreadFunc func, void* data) // can't tell the difference. if (!m_newThreadCalled) { m_newThreadCalled = true; +#if HAVE_PTHREAD_SIGNAL startSignalHandler(); +#endif } lockMutex(m_threadMutex); diff --git a/lib/arch/CArchNetworkBSD.cpp b/lib/arch/CArchNetworkBSD.cpp index 474c68fc..c83ad827 100644 --- a/lib/arch/CArchNetworkBSD.cpp +++ b/lib/arch/CArchNetworkBSD.cpp @@ -327,7 +327,7 @@ CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout) #else -void +int CArchNetworkBSD::pollSocket(CPollEntry pe[], int num, double timeout) { int i, n; @@ -765,8 +765,10 @@ CArchNetworkBSD::throwError(int err) case ENODEV: case ENOBUFS: case ENOMEM: - case ENOSR: case ENETDOWN: +#if defined(ENOSR) + case ENOSR: +#endif throw XArchNetworkResource(new XArchEvalUnix(err)); case EPROTOTYPE: @@ -777,8 +779,10 @@ CArchNetworkBSD::throwError(int err) case EINVAL: case ENOPROTOOPT: case EOPNOTSUPP: - case ENOPKG: case ESHUTDOWN: +#if defined(ENOPKG) + case ENOPKG: +#endif throw XArchNetworkSupport(new XArchEvalUnix(err)); case EIO: diff --git a/lib/arch/CArchNetworkBSD.h b/lib/arch/CArchNetworkBSD.h index 23d971bc..9718d71b 100644 --- a/lib/arch/CArchNetworkBSD.h +++ b/lib/arch/CArchNetworkBSD.h @@ -22,14 +22,7 @@ #endif #if !defined(HAVE_SOCKLEN_T) -// Darwin is so unsure what to use for socklen_t it makes us choose -# if defined(__APPLE__) -# if !defined(_BSD_SOCKLEN_T_) -# define _BSD_SOCKLEN_T_ int -# endif -# else typedef int socklen_t; -# endif #endif #define ARCH_NETWORK CArchNetworkBSD diff --git a/lib/arch/CArchSleepUnix.cpp b/lib/arch/CArchSleepUnix.cpp index 1e5675f4..35010721 100644 --- a/lib/arch/CArchSleepUnix.cpp +++ b/lib/arch/CArchSleepUnix.cpp @@ -69,7 +69,7 @@ CArchSleepUnix::sleep(double timeout) ARCH->testCancelThread(); #else /* emulate nanosleep() with select() */ - double startTime = time(); + double startTime = ARCH->time(); double timeLeft = timeout; while (timeLeft > 0.0) { struct timeval timeout2; @@ -82,7 +82,7 @@ CArchSleepUnix::sleep(double timeout) SELECT_TYPE_ARG234 NULL, SELECT_TYPE_ARG5 &timeout2); ARCH->testCancelThread(); - timeLeft = timeout - (time() - startTime); + timeLeft = timeout - (ARCH->time() - startTime); } #endif } diff --git a/lib/arch/CMultibyteEmu.cpp b/lib/arch/CMultibyteEmu.cpp index 80569fe5..0fd3087a 100644 --- a/lib/arch/CMultibyteEmu.cpp +++ b/lib/arch/CMultibyteEmu.cpp @@ -14,11 +14,42 @@ #include "CArch.h" #include -#include +#if HAVE_WCHAR_H +# include +#elif __APPLE__ + // wtf? Darwin puts mbtowc() et al. in stdlib +# include +#else + // platform apparently has no wchar_t support. provide dummy + // implementations. hopefully at least the C++ compiler has + // a built-in wchar_t type. +# undef HAVE_MBSINIT + +static inline +int +mbtowc(wchar_t* dst, const char* src, int n) +{ + *dst = static_cast(*src); + return 1; +} + +static inline +int +wctomb(char* dst, wchar_t src) +{ + *dst = static_cast(src); + return 1; +} + +#endif class CArchMBStateImpl { public: +#if HAVE_MBSINIT mbstate_t m_mbstate; +#else + int m_mbstate; // dummy data +#endif }; // @@ -50,7 +81,9 @@ ARCH_STRING::initMBState(CArchMBState state) bool ARCH_STRING::isInitMBState(CArchMBState state) { -#if !HAVE_MBSINIT + // if we're using this file mbsinit() probably doesn't exist + // but use it if it does +#if HAVE_MBSINIT return (mbsinit(&state->m_mbstate) != 0); #else return true; diff --git a/lib/common/Makefile.am b/lib/common/Makefile.am index 8a6abc21..4de7af6c 100644 --- a/lib/common/Makefile.am +++ b/lib/common/Makefile.am @@ -17,14 +17,6 @@ VDEPTH = ./$(VPATH)/$(DEPTH) EXTRA_DIST = \ common.dsp \ - $(NULL) - -MAINTAINERCLEANFILES = \ - Makefile.in \ - $(NULL) - -noinst_LIBRARIES = libcommon.a -libcommon_a_SOURCES = \ BasicTypes.h \ IInterface.h \ Version.h \ @@ -41,5 +33,10 @@ libcommon_a_SOURCES = \ stdstring.h \ stdvector.h \ $(NULL) + +MAINTAINERCLEANFILES = \ + Makefile.in \ + $(NULL) + INCLUDES = \ $(NULL)