Fixes to support FreeBSD and Darwin.
This commit is contained in:
parent
4bf0836eae
commit
a14a462e22
11
acinclude.m4
11
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 <pthread.h>
|
||||
#include <signal.h>],
|
||||
[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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -14,11 +14,42 @@
|
|||
|
||||
#include "CArch.h"
|
||||
#include <string.h>
|
||||
#include <cwchar>
|
||||
#if HAVE_WCHAR_H
|
||||
# include <wchar.h>
|
||||
#elif __APPLE__
|
||||
// wtf? Darwin puts mbtowc() et al. in stdlib
|
||||
# include <stdlib.h>
|
||||
#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<wchar_t>(*src);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline
|
||||
int
|
||||
wctomb(char* dst, wchar_t src)
|
||||
{
|
||||
*dst = static_cast<char>(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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue