summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriele Svelto <gabriele.svelto@gmail.com>2012-04-17 22:50:30 +0200
committerMartin Sustrik <sustrik@250bpm.com>2012-04-21 07:30:16 +0200
commit0a12aa09b65c67033b5021057dd04fde0a3cabb5 (patch)
tree269d991abda829e40cced4c53fa1a26d7b5dfc29
parentf4149b0500b8011c58cd3f5acbb4225dd79e8b85 (diff)
Change the way the polling system is selected
All polling systems are now checked and corresponding macros set accordingly (e.g. detection of a working poll() function will define XS_HAVE_POLL). Additionally if the user selects a specific polling system via the --with-poller switch a corresponding XS_FORCE_* macro will be defined. The select() and poll() tests now conditionally include headers which makes them more robust on various target platforms. Signed-off-by: Gabriele Svelto <gabriele.svelto@gmail.com>
-rw-r--r--acinclude.m4296
-rw-r--r--configure.ac78
2 files changed, 219 insertions, 155 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 169c786..e1429e5 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -603,109 +603,171 @@ int main (int argc, char *argv [])
)
}])
-dnl ################################################################################
-dnl # LIBXS_CHECK_POLLER_KQUEUE([action-if-found], [action-if-not-found]) #
-dnl # Checks kqueue polling system #
-dnl ################################################################################
-AC_DEFUN([LIBXS_CHECK_POLLER_KQUEUE], [{
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [
+###############################################################################
+# LIBXS_CHECK_KQUEUE #
+# Checks for kqueue() and defines XS_HAVE_KQUEUE if it is found #
+###############################################################################
+
+AC_DEFUN([LIBXS_CHECK_KQUEUE], [
+ AH_TEMPLATE([XS_HAVE_KQUEUE], [Defined to 1 if your system has kqueue()])
+
+ AS_VAR_PUSHDEF([ac_var], [acx_cv_have_kqueue])
+ AC_CACHE_CHECK([for kqueue()], [ac_var], [
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
- ],
-[[
+ ], [[
struct kevent t_kev;
kqueue();
-]]
- )],
- [libxs_cv_have_poller_kqueue="yes" ; $1],
- [libxs_cv_have_poller_kqueue="no" ; $2])
-}])
+ ]]
+ )],
+ [AS_VAR_SET([ac_var], [yes])],
+ [AS_VAR_SET([ac_var], [no])])])
+ AS_IF([test yes = AS_VAR_GET([ac_var])], [AC_DEFINE([XS_HAVE_KQUEUE], [1])])
+ AS_VAR_POPDEF([ac_var])
+])
+
+###############################################################################
+# LIBXS_CHECK_EPOLL #
+# Checks for epoll() and defines XS_HAVE_EPOLL if it is found #
+###############################################################################
+
+AC_DEFUN([LIBXS_CHECK_EPOLL], [
+ AH_TEMPLATE([XS_HAVE_EPOLL], [Defined to 1 if your system has epoll()])
-dnl ################################################################################
-dnl # LIBXS_CHECK_POLLER_EPOLL([action-if-found], [action-if-not-found]) #
-dnl # Checks epoll polling system #
-dnl ################################################################################
-AC_DEFUN([LIBXS_CHECK_POLLER_EPOLL], [{
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [
+ AS_VAR_PUSHDEF([ac_var], [acx_cv_have_epoll])
+ AC_CACHE_CHECK([for epoll()], [ac_var], [
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
#include <sys/epoll.h>
- ],
-[[
+ ], [[
struct epoll_event t_ev;
epoll_create(10);
-]]
- )],
- [libxs_cv_have_poller_epoll="yes" ; $1],
- [libxs_cv_have_poller_epoll="no" ; $2])
-}])
+ ]]
+ )],
+ [AS_VAR_SET([ac_var], [yes])],
+ [AS_VAR_SET([ac_var], [no])])])
+ AS_IF([test yes = AS_VAR_GET([ac_var])], [AC_DEFINE([XS_HAVE_EPOLL], [1])])
+ AS_VAR_POPDEF([ac_var])
+])
+
+###############################################################################
+# LIBXS_CHECK_DEVPOLL #
+# Checks for /dev/poll and defines XS_HAVE_DEVPOLL if it is found #
+###############################################################################
+
+AC_DEFUN([LIBXS_CHECK_DEVPOLL], [
+ AH_TEMPLATE([XS_HAVE_DEVPOLL], [Defined to 1 if your system has /dev/poll])
-dnl ################################################################################
-dnl # LIBXS_CHECK_POLLER_DEVPOLL([action-if-found], [action-if-not-found]) #
-dnl # Checks devpoll polling system #
-dnl ################################################################################
-AC_DEFUN([LIBXS_CHECK_POLLER_DEVPOLL], [{
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [
+ AS_VAR_PUSHDEF([ac_var], [acx_cv_have_devpoll])
+ AC_CACHE_CHECK([for /dev/poll], [ac_var], [
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/poll.h>
#include <sys/devpoll.h>
- ],
-[[
+ ], [[
struct dvpoll p;
p.dp_timeout = 0;
p.dp_nfds = 0;
p.dp_fds = (struct pollfd *) 0;
return 0;
-]]
- )],
- [libxs_cv_have_poller_devpoll="yes" ; $1],
- [libxs_cv_have_poller_devpoll="no" ; $2])
-}])
+ ]]
+ )],
+ [AS_VAR_SET([ac_var], [yes])],
+ [AS_VAR_SET([ac_var], [no])])])
+ AS_IF([test yes = AS_VAR_GET([ac_var])], [
+ AC_DEFINE([XS_HAVE_DEVPOLL], [1])
+ ])
+ AS_VAR_POPDEF([ac_var])
+])
-dnl ################################################################################
-dnl # LIBXS_CHECK_POLLER_POLL([action-if-found], [action-if-not-found]) #
-dnl # Checks poll polling system #
-dnl ################################################################################
-AC_DEFUN([LIBXS_CHECK_POLLER_POLL], [{
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [
-#include <poll.h>
- ],
-[[
+###############################################################################
+# LIBXS_CHECK_POLL #
+# Checks for poll() and defines XS_HAVE_POLL if it is found #
+###############################################################################
+
+AC_DEFUN([LIBXS_CHECK_POLL], [
+ AH_TEMPLATE([XS_HAVE_POLL], [Defined to 1 if your system has poll()])
+
+ AC_CHECK_HEADERS([ \
+ poll.h \
+ sys/types.h \
+ sys/select.h \
+ sys/poll.h
+ ])
+
+ AS_VAR_PUSHDEF([ac_var], [acx_cv_have_poll])
+ AC_CACHE_CHECK([for poll()], [ac_var], [
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
+#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+
+#if HAVE_SYS_SELECT_H
+# include <sys/select.h>
+#endif
+
+#if HAVE_SYS_POLL_H
+# include <sys/poll.h>
+#elif HAVE_POLL_H
+# include <poll.h>
+#endif
+ ], [[
struct pollfd t_poll;
poll(&t_poll, 1, 1);
-]]
- )],
- [libxs_cv_have_poller_poll="yes" ; $1],
- [libxs_cv_have_poller_poll="no" ; $2])
-}])
+ ]]
+ )],
+ [AS_VAR_SET([ac_var], [yes])],
+ [AS_VAR_SET([ac_var], [no])])])
+ AS_IF([test yes = AS_VAR_GET([ac_var])], [AC_DEFINE([XS_HAVE_POLL], [1])])
+ AS_VAR_POPDEF([ac_var])
+])
+
+###############################################################################
+# LIBXS_CHECK_SELECT #
+# Checks for select() and defines XS_HAVE_SELECT if it is found #
+###############################################################################
+
+AC_DEFUN([LIBXS_CHECK_SELECT], [
+ AH_TEMPLATE([XS_HAVE_SELECT], [Defined to 1 if your system has select()])
-dnl ################################################################################
-dnl # LIBXS_CHECK_POLLER_SELECT([action-if-found], [action-if-not-found]) #
-dnl # Checks select polling system #
-dnl ################################################################################
-AC_DEFUN([LIBXS_CHECK_POLLER_SELECT], [{
- AC_LINK_IFELSE(
- [AC_LANG_PROGRAM(
- [
+ AC_CHECK_HEADERS([ \
+ unistd.h \
+ sys/types.h \
+ sys/time.h \
+ sys/select.h
+ ])
+
+ AS_VAR_PUSHDEF([ac_var], [acx_cv_have_select])
+ AC_CACHE_CHECK([for select()], [ac_var], [
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([
#ifdef XS_HAVE_WINDOWS
-#include "winsock2.h"
-#elif defined XS_HAVE_OPENVMS
-#include <sys/types.h>
-#include <sys/time.h>
+# include "winsock2.h"
#else
-#include <sys/select.h>
+# if HAVE_UNISTD_H
+# include <unistd.h>
+# endif
+#
+# if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+# endif
+#
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# endif
+#
+# if HAVE_SYS_SELECT_H
+# include <sys/select.h>
+# endif
#endif
- ],
-[[
+ ], [[
fd_set t_rfds;
struct timeval tv;
@@ -716,79 +778,11 @@ tv.tv_sec = 5;
tv.tv_usec = 0;
select(1, &t_rfds, NULL, NULL, &tv);
-]]
- )],
- [libxs_cv_have_poller_select="yes" ; $1],
- [libxs_cv_have_poller_select="no" ; $2])
-}])
-
-dnl ################################################################################
-dnl # LIBXS_CHECK_POLLER([action-if-found], [action-if-not-found]) #
-dnl # Choose polling system #
-dnl ################################################################################
-AC_DEFUN([LIBXS_CHECK_POLLER], [{
-
- # Templates to be picked up by autoheader
- AH_TEMPLATE([XS_HAVE_KQUEUE], [Defined to 1 if your system has kqueue()])
- AH_TEMPLATE([XS_HAVE_EPOLL], [Defined to 1 if your system has epoll()])
- AH_TEMPLATE([XS_HAVE_DEVPOLL], [Defined to 1 if your system has /dev/poll])
- AH_TEMPLATE([XS_HAVE_POLL], [Defined to 1 if your system has poll()])
- AH_TEMPLATE([XS_HAVE_SELECT], [Defined to 1 if your system has select()])
-
- # Allow user to disable doc build
- AC_ARG_WITH([poller], [AS_HELP_STRING([--with-poller],
- [choose polling system manually. valid values are kqueue, epoll, devpoll, poll or select [default=autodetect]])])
-
- AC_MSG_CHECKING([for suitable polling system])
-
- case "${with_poller}" in
- kqueue|epoll|devpoll|poll|select)
- # User has chosen polling system
- libxs_cv_poller="${with_poller}"
- ;;
-
- *)
- # try to find suitable polling system. the order of testing is:
- # kqueue -> epoll -> devpoll -> poll -> select
- for subsystem in kqueue epoll devpoll poll select; do
-
- case "${subsystem}" in
- kqueue)
- LIBXS_CHECK_POLLER_KQUEUE([libxs_cv_poller=$subsystem], [])
- ;;
-
- epoll)
- LIBXS_CHECK_POLLER_EPOLL([libxs_cv_poller=$subsystem], [])
- ;;
-
- devpoll)
- LIBXS_CHECK_POLLER_DEVPOLL([libxs_cv_poller=$subsystem], [])
- ;;
-
- poll)
- LIBXS_CHECK_POLLER_POLL([libxs_cv_poller=$subsystem], [])
- ;;
-
- select)
- LIBXS_CHECK_POLLER_SELECT([libxs_cv_poller=$subsystem], [])
- ;;
- esac
-
- if test "x${libxs_cv_poller}" != "x"; then
- break
- fi
- done
- ;;
- esac
-
- AS_IF([test "x${libxs_cv_poller}" != "x"], [
- AC_MSG_RESULT([using $libxs_cv_poller])
- $1
- ], [
- AC_MSG_RESULT([no suitable polling system found])
- $2
- ])
-
- AC_DEFINE_UNQUOTED(AS_TR_CPP(xs_have_${libxs_cv_poller}))
-}])
+ ]]
+ )],
+ [AS_VAR_SET([ac_var], [yes])],
+ [AS_VAR_SET([ac_var], [no])])])
+ AS_IF([test yes = AS_VAR_GET([ac_var])], [AC_DEFINE([XS_HAVE_SELECT], [1])])
+ AS_VAR_POPDEF([ac_var])
+])
diff --git a/configure.ac b/configure.ac
index 8156cbe..b602df5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -220,10 +220,6 @@ AS_CASE(["${host_cpu}"],
# Check whether to build docs / install man pages
LIBXS_CHECK_DOC_BUILD
-# Check polling system
-LIBXS_CHECK_POLLER([],
- [AC_MSG_ERROR([Unable to continue without polling system])])
-
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([ \
@@ -245,6 +241,80 @@ AC_CHECK_HEADERS([ \
AC_CHECK_HEADERS([ifaddrs.h],
[AC_DEFINE([XS_HAVE_IFADDRS], [1], [Have ifaddrs.h header.])])
+###############################################################################
+# Check polling system #
+###############################################################################
+
+# Allow users to override the polling system
+AC_ARG_WITH([poller],
+ [AS_HELP_STRING([--with-poller],
+ [choose polling system manually. valid values are kqueue, epoll, devpoll, poll or select [default=autodetect]])],
+ [], [with_poller=autodetect])
+
+# Check the various polling systems
+LIBXS_CHECK_KQUEUE
+LIBXS_CHECK_EPOLL
+LIBXS_CHECK_DEVPOLL
+LIBXS_CHECK_POLL
+LIBXS_CHECK_SELECT
+
+# Select the best available poller
+AS_CASE([${with_poller}],
+ [kqueue], [
+ AS_IF([test x$acx_cv_have_kqueue != xyes], [
+ AC_MSG_ERROR([kqueue() poller selected but not available])
+ ])
+ AC_DEFINE([XS_FORCE_KQUEUE], [1], [Forces use of kqueue()])
+ libxs_cv_poller=kqueue
+ ],
+ [epoll], [
+ AS_IF([test x$acx_cv_have_epoll != xyes], [
+ AC_MSG_ERROR([epoll() poller selected but not available])
+ ])
+ AC_DEFINE([XS_FORCE_EPOLL], [1], [Forces use of epoll()])
+ libxs_cv_poller=epoll
+ ],
+ [devpoll], [
+ AS_IF([test x$acx_cv_have_devpoll != xyes], [
+ AC_MSG_ERROR([/dev/poll poller selected but not available])
+ ])
+ AC_DEFINE([XS_FORCE_DEVPOLL], [1], [Forces use of /dev/poll])
+ libxs_cv_poller=devpoll
+ ],
+ [poll], [
+ AS_IF([test x$acx_cv_have_poll != xyes], [
+ AC_MSG_ERROR([poll() poller selected but not available])
+ ])
+ AC_DEFINE([XS_FORCE_POLL], [1], [Forces use of poll()])
+ libxs_cv_poller=poll
+ ],
+ [select], [
+ AS_IF([test x$acx_cv_have_select != xyes], [
+ AC_MSG_ERROR([select() poller selected but not available])
+ ])
+ AC_DEFINE([XS_FORCE_SELECT], [1], [Forces use of select()])
+ libxs_cv_poller=select
+ ],
+ [autodetect], [
+ AS_IF([test x$acx_cv_have_kqueue = xyes], [
+ libxs_cv_poller=kqueue
+ ], [test x$acx_cv_have_epoll = xyes], [
+ libxs_cv_poller=epoll
+ ], [test x$acx_cv_have_devpoll = xyes], [
+ libxs_cv_poller=devpoll
+ ], [test x$acx_cv_have_poll = xyes], [
+ libxs_cv_poller=poll
+ ], [test x$acx_cv_have_select = xyes], [
+ libxs_cv_poller=select
+ ], [
+ AC_MSG_ERROR([no suitable polling system found])
+ ])
+ ],
+ [*], [
+ AC_MSG_ERROR([Invalid poller selected: ${with_poller}])
+ ]
+)
+
# Force not to use eventfd
AC_ARG_ENABLE([eventfd],
[AS_HELP_STRING([--disable-eventfd], [disable eventfd [default=no]])],