---------------------
PatchSet 10845 
Date: 2007/06/10 12:07:28
Author: hno
Branch: HEAD
Tag: (none) 
Log:
Clean up configure magics selecting which comm loop to use, promote epoll to stable

This is basically a copy from Squid-2, making configure a bit smarter
in selecting which comm loop to use, and automatically enabling epoll
if it seems usable.

kqueue is still not activated automatically even if defected as the
comm_kqueue implementation is still experimental and known to have issues

Members: 
	configure.in:1.456->1.457 

Index: squid3/configure.in
===================================================================
RCS file: /cvsroot/squid/squid3/configure.in,v
retrieving revision 1.456
retrieving revision 1.457
diff -u -r1.456 -r1.457
--- squid3/configure.in	2 Jun 2007 23:46:00 -0000	1.456
+++ squid3/configure.in	10 Jun 2007 12:07:28 -0000	1.457
@@ -1,7 +1,7 @@
 
 dnl  Configuration input file for Squid
 dnl
-dnl  $Id: configure.in,v 1.456 2007/06/02 23:46:00 hno Exp $
+dnl  $Id: configure.in,v 1.457 2007/06/10 12:07:28 hno Exp $
 dnl
 dnl
 dnl
@@ -11,7 +11,7 @@
 AC_CONFIG_AUX_DIR(cfgaux)
 AC_CONFIG_SRCDIR([src/main.cc])
 AM_INIT_AUTOMAKE([tar-ustar])
-AC_REVISION($Revision: 1.456 $)dnl
+AC_REVISION($Revision: 1.457 $)dnl
 AC_PREFIX_DEFAULT(/usr/local/squid)
 AM_MAINTAINER_MODE
 
@@ -1060,6 +1060,7 @@
   yes)
     echo "Forcing poll() to be enabled"
     ac_cv_func_poll='yes'
+    SELECT_TYPE="poll"
     ;;
   no)
     echo "Forcing poll() to be disabled"
@@ -1078,6 +1079,7 @@
   yes)
     echo "Forcing select() to be enabled"
     ac_cv_func_select='yes'
+    SELECT_TYPE="select"
     ;;
   no)
     echo "Forcing select() to be disabled"
@@ -1096,6 +1098,7 @@
   yes)
     echo "Forcing kqueue() to be enabled"
     ac_cv_func_kqueue='yes'
+    SELECT_TYPE="kqueue"
     ;;
   no)
     echo "Forcing kqueue() to be disabled"
@@ -1113,11 +1116,12 @@
   case "$enableval" in
   yes)
     echo "Forcing epoll() to be enabled"
-    ac_cv_func_epoll='yes'
+    ac_cv_func_epoll_ctl='yes'
+    SELECT_TYPE="epoll"
     ;;
   no)
     echo "Forcing epoll() to be disabled"
-    ac_cv_func_epoll='no'
+    ac_cv_func_epoll_ctl='no'
   ;;
 esac
 ])
@@ -2569,6 +2573,7 @@
 	gettimeofday \
 	htobe16 \
 	htole16 \
+	kqueue\
 	lrand48 \
 	mallinfo \
 	mallocblksize \
@@ -2612,32 +2617,64 @@
 	vsnprintf \
 )
 
+# Check for libepoll
+EPOLL_LIB=
+AC_CHECK_LIB(epoll, epoll_ctl, [EPOLL_LIBS="-lepoll"])
+AC_SUBST(EPOLL_LIBS)
+
+# Check for epoll_ctl, may need -lepoll
+SAVED_LIBS="$LIBS"
+LIBS="$LIBS $LIB_EPOLL"
+AC_CHECK_FUNCS(epoll_ctl)
+LIBS="$SAVED_LIBS"
+
+dnl Verify that epoll really works
+if test $ac_cv_func_epoll_ctl = yes; then
+  AC_CACHE_CHECK(if epoll works, ac_cv_epoll_works,
+    AC_TRY_RUN([
+#include <sys/epoll.h>
+#include <stdlib.h>
+#include <stdio.h>
+int main(int argc, char **argv)
+{
+    int fd = epoll_create(256);
+    if (fd < 0) {
+	perror("epoll_create:");
+	exit(1);
+    }
+    exit(0);
+}
+    ], [ac_cv_epoll_works=yes], [ac_cv_epoll_works=no]))
+  if test ac_cv_epoll_works = no && test ac_force_epoll = yes; then
+	echo "Error - no epoll found";
+	echo "Try running 'sh ./scripts/get_epoll-lib.sh'";
+	echo "then run configure again";
+	exit -1
+  fi
+fi
+
 dnl Magic which checks whether we are forcing a type of comm loop we
 dnl are actually going to (ab)use
  
 dnl Actually do the define magic now
 dnl mostly ripped from squid-commloops, thanks to adrian and benno
 
-if test "$ac_cv_func_kqueue" = "yes" ; then
-	SELECT_TYPE="kqueue"
-	AC_DEFINE(USE_KQUEUE,1,[Use kqueue() for the IO loop])
-elif test "$ac_cv_func_epoll" = "yes" ; then
+if test -n "$SELECT_TYPE"; then
+	: # Already decided above. Nothing to do here
+elif test "$ac_cv_epoll_works" = "yes" ; then
 	SELECT_TYPE="epoll"
-	AC_DEFINE(USE_EPOLL,1,[Use epoll() for the IO loop])
-	AC_CHECK_LIB(epoll, epoll_create, [EPOLL_LIBS="-lepoll"])
-	AC_SUBST(EPOLL_LIBS)
+#comm_kqueue a bit broken. Don't enable automatically
+#elif test "$ac_cv_func_kqueue" = "yes" ; then
+#	SELECT_TYPE="kqueue"
 elif test "$ac_cv_func_poll" = "yes" ; then
         SELECT_TYPE="poll"
-        AC_DEFINE(USE_POLL,1,[Use poll() for the IO loop])
 elif test "$ac_cv_func_select" = "yes" ; then
 	case "$host_os" in
 	mingw|mingw32)
 	        SELECT_TYPE="select_win32"
-	        AC_DEFINE(USE_SELECT_WIN32,1,[Use Winsock select() for the IO loop])
 		;;
 	*)
 	        SELECT_TYPE="select"
-	        AC_DEFINE(USE_SELECT,1,[Use select() for the IO loop])
 		;;
 	esac
 else
@@ -2646,7 +2683,34 @@
         SELECT_TYPE="select"
         AC_DEFINE(USE_SELECT,1)
 fi
-echo "Using ${SELECT_TYPE} for select loop."
+
+echo "Using ${SELECT_TYPE} for the IO loop."
+
+AM_CONDITIONAL([USE_POLL], [test $SELECT_TYPE = poll])
+AM_CONDITIONAL([USE_EPOLL], [test $SELECT_TYPE = epoll])
+AM_CONDITIONAL([USE_SELECT], [test $SELECT_TYPE = select])
+AM_CONDITIONAL([USE_SELECT_SIMPLE], [test $SELECT_TYPE = select_simple])
+AM_CONDITIONAL([USE_SELECT_WIN32], [test $SELECT_TYPE = select_win32])
+AM_CONDITIONAL([USE_KQUEUE], [test $SELECT_TYPE = kqueue])
+AM_CONDITIONAL([USE_DEVPOLL], [test $SELECT_TYPE = devpoll])
+
+case $SELECT_TYPE in
+epoll)
+	AC_DEFINE(USE_EPOLL,1,[Use epoll() for the IO loop])
+	;;
+poll)
+        AC_DEFINE(USE_POLL,1,[Use poll() for the IO loop])
+	;;
+kqueue)
+	AC_DEFINE(USE_KQUEUE,1,[Use kqueue() for the IO loop])
+	;;
+select_win32)
+	AC_DEFINE(USE_SELECT_WIN32,1,[Use Winsock select() for the IO loop])
+	;;
+select)
+	AC_DEFINE(USE_SELECT,1,[Use select() for the IO loop])
+	;;
+esac
 
 
 dnl Yay!  Another Linux brokenness.  Its not good enough
