Commit Diff


commit - ee568cc4440015b45d7fd12b00974c4d1fba658c
commit + 5c782302835e19ac1373ccd574070b8ff9003517
blob - e16e248444a455aca7319c6340fadf08df013d25
blob + f723e2bcf516da90ad3c99989b7d0f691b7ec00b
--- ChangeLog
+++ ChangeLog
@@ -12,6 +12,10 @@
 
 ngIRCd HEAD
 
+  - When using epoll() IO interface, compile in the select() interface as
+    well and fall back to it when epoll() isn't available on runtime.
+  - New configure option "--without-select" to disable select() IO API
+    (even when using epoll(), see above).
   - Added support for IO APIs "poll()" and "/dev/poll".
   - Reorganized internal handling of invite and ban lists.
 
@@ -678,4 +682,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
-$Id: ChangeLog,v 1.311 2006/12/17 21:00:30 alex Exp $
+$Id: ChangeLog,v 1.312 2006/12/26 16:00:45 alex Exp $
blob - 9b2c7128fa259c642d4d199b665a8380ca6a6a7d
blob + 51841e7a862ac236c42867833b6ca7d736d724a7
--- configure.in
+++ configure.in
@@ -8,7 +8,7 @@
 # (at your option) any later version.
 # Please read the file COPYING, README and AUTHORS for more information.
 #
-# $Id: configure.in,v 1.124 2006/10/02 21:57:13 fw Exp $
+# $Id: configure.in,v 1.125 2006/12/26 16:00:45 alex Exp $
 #
 
 # -- Initialisation --
@@ -143,12 +143,10 @@ AC_CHECK_FUNCS([ \
 
 AC_CHECK_FUNCS(inet_aton isdigit sigaction snprintf vsnprintf strdup strlcpy strlcat)
 
-AC_CHECK_FUNCS(select,[AC_CHECK_HEADERS(sys/select.h)],
-	AC_MSG_ERROR([required function select() is missing!])
-)
-
 # -- Configuration options --
 
+# use syslog?
+
 x_syslog_on=no
 AC_ARG_WITH(syslog,
 	[  --without-syslog        disable syslog (autodetected by default)],
@@ -174,6 +172,8 @@ if test "$x_syslog_on" = "yes"; then
 	AC_CHECK_HEADERS(syslog.h,,AC_MSG_ERROR([required C header missing!]))
 fi
 
+# use zlib compression?
+
 x_zlib_on=no
 AC_ARG_WITH(zlib,
 	[  --without-zlib          disable zlib compression (autodetected by default)],
@@ -198,8 +198,28 @@ if test "$x_zlib_on" = "yes"; then
 	AC_CHECK_HEADERS(zlib.h,,AC_MSG_ERROR([required C header missing!]))
 fi
 
+# detect which IO API to use:
 
-x_io_backend=select\(\)
+x_io_backend=none
+
+AC_ARG_WITH(select,
+	[  --without-select        disable select IO support (autodetected by default)],
+	[	if test "$withval" != "no"; then
+			if test "$withval" != "yes"; then
+				CFLAGS="-I$withval/include $CFLAGS"
+				CPPFLAGS="-I$withval/include $CPPFLAGS"
+				LDFLAGS="-L$withval/lib $LDFLAGS"
+			fi
+			AC_CHECK_FUNCS(select, x_io_select=yes,
+				AC_MSG_ERROR([Can't enable select IO support!])
+			)
+		fi
+	],
+	[
+		AC_CHECK_FUNCS(select, x_io_select=yes)
+	]
+)
+
 AC_ARG_WITH(poll,
 	[  --without-poll          disable poll support (autodetected by default)],
 	[	if test "$withval" != "no"; then
@@ -209,7 +229,7 @@ AC_ARG_WITH(poll,
 				LDFLAGS="-L$withval/lib $LDFLAGS"
 			fi
 			AC_CHECK_FUNCS(poll, x_io_backend=poll\(\),
-				AC_MSG_ERROR([Can't enable poll support!])
+				AC_MSG_ERROR([Can't enable poll IO support!])
 			)
 		fi
 	],
@@ -218,9 +238,8 @@ AC_ARG_WITH(poll,
 	]
 )
 
-
 AC_ARG_WITH(devpoll,
-	[  --without-devpoll          disable /dev/poll support (autodetected by default)],
+	[  --without-devpoll       disable /dev/poll IO support (autodetected by default)],
 	[	if test "$withval" != "no"; then
 			if test "$withval" != "yes"; then
 				CFLAGS="-I$withval/include $CFLAGS"
@@ -232,31 +251,30 @@ AC_ARG_WITH(devpoll,
 		fi
 	],
 	[
-		AC_CHECK_HEADERS(sys/devpoll.h,x_io_backend=/dev/poll,)
+		AC_CHECK_HEADERS(sys/devpoll.h, x_io_backend=/dev/poll)
 	]
 )
 
 AC_ARG_WITH(epoll,
-	[  --without-epoll         disable epoll support (autodetected by default)],
+	[  --without-epoll         disable epoll IO support (autodetected by default)],
 	[	if test "$withval" != "no"; then
 			if test "$withval" != "yes"; then
 				CFLAGS="-I$withval/include $CFLAGS"
 				CPPFLAGS="-I$withval/include $CPPFLAGS"
 				LDFLAGS="-L$withval/lib $LDFLAGS"
 			fi
-			AC_CHECK_FUNCS(epoll_create, x_io_backend=epoll\(\),
-				AC_MSG_ERROR([Can't enable epoll support!])
+			AC_CHECK_FUNCS(epoll_create, x_io_epoll=yes,
+				AC_MSG_ERROR([Can't enable epoll IO support!])
 			)
 		fi
 	],
 	[
-		AC_CHECK_FUNCS(epoll_create, x_io_backend=epoll\(\))
+		AC_CHECK_FUNCS(epoll_create, x_io_epoll=yes)
 	]
 )
 
-
 AC_ARG_WITH(kqueue,
-	[  --without-kqueue        disable kqueue support (autodetected by default)],
+	[  --without-kqueue        disable kqueue IO support (autodetected by default)],
 	[	if test "$withval" != "no"; then
 			if test "$withval" != "yes"; then
 				CFLAGS="-I$withval/include $CFLAGS"
@@ -264,7 +282,7 @@ AC_ARG_WITH(kqueue,
 				LDFLAGS="-L$withval/lib $LDFLAGS"
 			fi
 			AC_CHECK_FUNCS(kqueue, x_io_backend=kqueue\(\),
-				AC_MSG_ERROR([Can't enable kqueue support!])
+				AC_MSG_ERROR([Can't enable kqueue IO support!])
 			)
 		fi
 	],
@@ -272,8 +290,29 @@ AC_ARG_WITH(kqueue,
 		AC_CHECK_FUNCS(kqueue, x_io_backend=kqueue\(\))
 	]
 )
+
+if test "$x_io_epoll" = "yes" -a "$x_io_select" = "yes"; then
+	# when epoll() and select() are available, we'll use both!
+	x_io_backend="epoll(), select()"
+else
+	if test "$x_io_epoll" = "yes"; then
+		# we prefere epoll() if it is available
+		x_io_backend="epoll()"
+	else
+		if test "$x_io_select" = "yes" -a "$x_io_backend" = "none"; then
+			# we'll use select, when available and no "better"
+			# interface has been detected ...
+			x_io_backend="select()"
+		fi
+	fi
+fi
 
+if test "$x_io_backend" = "none"; then
+	AC_MSG_ERROR([No useabe IO API activated/found!?])
+fi
 
+# use TCP wrappers?
+
 x_tcpwrap_on=no
 AC_ARG_WITH(tcp-wrappers,
 	[  --with-tcp-wrappers     enable TCP wrappers support],
@@ -302,6 +341,8 @@ int deny_severity = 0;
 		fi
 	]
 )
+
+# include support for "zeroconf"?
 
 x_zeroconf_on=no
 AC_ARG_WITH(zeroconf,
@@ -351,6 +392,8 @@ if test "$x_zeroconf_on" = "howl"; then
 	AC_DEFINE(ZEROCONF, 1)
 fi
 
+# do IDENT requests using libident?
+
 x_identauth_on=no
 AC_ARG_WITH(ident,
 	[  --with-ident            enable "IDENT" ("AUTH") protocol support],
@@ -372,6 +415,8 @@ if test "$x_identauth_on" = "yes"; then
 	AC_CHECK_HEADERS(ident.h,,AC_MSG_ERROR([required C header missing!]))
 fi
 
+# compile in IRC+ protocol support?
+
 x_ircplus_on=yes
 AC_ARG_ENABLE(ircplus,
 	[  --disable-ircplus       disable IRC+ protocol],
@@ -381,6 +426,8 @@ if test "$x_ircplus_on" = "yes"; then
 	AC_DEFINE(IRCPLUS, 1)
 fi
 
+# compile in IRC "sniffer"?
+
 x_sniffer_on=no; x_debug_on=no
 AC_ARG_ENABLE(sniffer,
 	[  --enable-sniffer        enable IRC traffic sniffer (enables debug mode)],
@@ -390,6 +437,8 @@ AC_ARG_ENABLE(sniffer,
 	fi
 )
 
+# enable additional debugging code?
+
 AC_ARG_ENABLE(debug,
 	[  --enable-debug          show additional debug output],
 	if test "$enableval" = "yes"; then x_debug_on=yes; fi
@@ -399,6 +448,8 @@ if test "$x_debug_on" = "yes"; then
 	test "$GCC" = "yes" && CFLAGS="-pedantic $CFLAGS"
 fi
 
+# enable "strict RFC rules"?
+
 x_strict_rfc_on=no
 AC_ARG_ENABLE(strict-rfc,
 	[  --enable-strict-rfc     strict RFC conformance -- may break clients!],
blob - 61f73fdb2614991bb261faeded5c752b46170e79
blob + 71ec3b40ccc2c5035d224d1bc37da021b6ecf7ce
--- src/ngircd/io.c
+++ src/ngircd/io.c
@@ -12,7 +12,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: io.c,v 1.22 2006/12/16 22:48:34 fw Exp $";
+static char UNUSED id[] = "$Id: io.c,v 1.23 2006/12/26 16:00:46 alex Exp $";
 
 #include <assert.h>
 #include <stdlib.h>
@@ -34,33 +34,40 @@ typedef struct {
  short what;
 } io_event;
 
-#define INIT_IOEVENT    { NULL, -1, 0, NULL }
-#define IO_ERROR        4
+#define INIT_IOEVENT		{ NULL, -1, 0, NULL }
+#define IO_ERROR		4
 
 #ifdef HAVE_EPOLL_CREATE
-#define IO_USE_EPOLL    1
+#  define IO_USE_EPOLL		1
+#  ifdef HAVE_SELECT
+#    define IO_USE_SELECT	1
+#  endif
 #else
-# ifdef HAVE_KQUEUE
-#define IO_USE_KQUEUE   1
-# else
-#  ifdef HAVE_SYS_DEVPOLL_H
-#define IO_USE_DEVPOLL  1
-#   else
-#    ifdef HAVE_POLL
-#define IO_USE_POLL     1
+#  ifdef HAVE_KQUEUE
+#    define IO_USE_KQUEUE	1
+#  else
+#    ifdef HAVE_SYS_DEVPOLL_H
+#      define IO_USE_DEVPOLL	1
+#    else
+#      ifdef HAVE_POLL
+#        define IO_USE_POLL	1
+#      else
+#        ifdef HAVE_SELECT
+#          define IO_USE_SELECT	1
 #        else
-#define IO_USE_SELECT   1
+#          error "no IO API available!?"
+#        endif /* HAVE_SELECT */
 #      endif /* HAVE_POLL */
 #    endif /* HAVE_SYS_DEVPOLL_H */
-# endif /* HAVE_KQUEUE */
+#  endif /* HAVE_KQUEUE */
 #endif /* HAVE_EPOLL_CREATE */
 
-static bool library_initialized;
+static bool library_initialized = false;
 
 #ifdef IO_USE_EPOLL
 #include <sys/epoll.h>
 
-static int io_masterfd;
+static int io_masterfd = -1;
 static bool io_event_change_epoll(int fd, short what, const int action);
 static int io_dispatch_epoll(struct timeval *tv);
 #endif
@@ -101,7 +108,11 @@ static fd_set readers;
 static fd_set writers;
 static int select_maxfd;		/* the select() interface sucks badly */
 static int io_dispatch_select(struct timeval *tv);
+
+#ifndef IO_USE_EPOLL
+#define io_masterfd -1
 #endif
+#endif /* IO_USE_SELECT */
 
 static array io_events;
 
@@ -187,11 +198,12 @@ io_library_init_epoll(unsigned int eventsize)
 	if (ecreate_hint <= 0)
 		ecreate_hint = 128;
 	io_masterfd = epoll_create(ecreate_hint);
-	Log(LOG_INFO,
-	    "IO subsystem: epoll (hint size %d, initial maxfd %u, masterfd %d).",
-	    ecreate_hint, eventsize, io_masterfd);
-	if (io_masterfd >= 0)
+	if (io_masterfd >= 0) {
 		library_initialized = true;
+		Log(LOG_INFO,
+		    "IO subsystem: epoll (hint size %d, initial maxfd %u, masterfd %d).",
+		    ecreate_hint, eventsize, io_masterfd);
+	}
 }
 #endif
 
@@ -229,7 +241,11 @@ io_library_init(unsigned int eventsize)
 		eventsize = 0;
 #ifdef IO_USE_EPOLL
 	io_library_init_epoll(eventsize);
+#ifdef IO_USE_SELECT
+	if (io_masterfd < 0)
+		Log(LOG_INFO, "Can't initialize epoll() IO interface, falling back to select() ...");
 #endif
+#endif
 #ifdef IO_USE_KQUEUE
 	io_library_init_kqueue(eventsize);
 #endif
@@ -240,7 +256,8 @@ io_library_init(unsigned int eventsize)
 	io_library_init_poll(eventsize);
 #endif
 #ifdef IO_USE_SELECT
-	io_library_init_select(eventsize);
+	if (! library_initialized)
+		io_library_init_select(eventsize);
 #endif
 	return library_initialized;
 }
@@ -254,7 +271,8 @@ io_library_shutdown(void)
 	FD_ZERO(&writers);
 #endif
 #ifdef IO_USE_EPOLL
-	close(io_masterfd);
+	if (io_masterfd >= 0)
+		close(io_masterfd);
 	io_masterfd = -1;
 #endif
 #ifdef IO_USE_KQUEUE
@@ -316,7 +334,8 @@ io_event_create(int fd, short what, void (*cbfunc) (in
 	ret = io_event_change_kqueue(fd, what, EV_ADD|EV_ENABLE);
 #endif
 #ifdef IO_USE_SELECT
-	ret = io_event_add(fd, what);
+	if (io_masterfd < 0)
+		ret = io_event_add(fd, what);
 #endif
 	if (ret) i->what = what;
 	return ret;
@@ -450,7 +469,8 @@ io_event_add(int fd, short what)
 #endif
 	i->what |= what;
 #ifdef IO_USE_EPOLL
-	return io_event_change_epoll(fd, i->what, EPOLL_CTL_MOD);
+	if (io_masterfd >= 0)
+		return io_event_change_epoll(fd, i->what, EPOLL_CTL_MOD);
 #endif
 
 #ifdef IO_USE_KQUEUE
@@ -535,6 +555,10 @@ static void
 io_close_select(int fd)
 {
 	io_event *i;
+
+	if (io_masterfd >= 0)	/* Are we using epoll()? */
+		return;
+
 	FD_CLR(fd, &writers);
 	FD_CLR(fd, &readers);
 
@@ -606,7 +630,8 @@ io_event_del(int fd, short what)
 	return io_event_change_poll(fd, i->what);
 #endif
 #ifdef IO_USE_EPOLL
-	return io_event_change_epoll(fd, i->what, EPOLL_CTL_MOD);
+	if (io_masterfd >= 0)
+		return io_event_change_epoll(fd, i->what, EPOLL_CTL_MOD);
 #endif
 
 #ifdef IO_USE_KQUEUE
@@ -857,6 +882,10 @@ io_dispatch_kqueue(struct timeval *tv)
 int
 io_dispatch(struct timeval *tv)
 {
+#ifdef IO_USE_EPOLL
+	if (io_masterfd >= 0)
+		return io_dispatch_epoll(tv);
+#endif
 #ifdef IO_USE_SELECT
 	return io_dispatch_select(tv);
 #endif
@@ -869,9 +898,6 @@ io_dispatch(struct timeval *tv)
 #ifdef IO_USE_POLL
 	return io_dispatch_poll(tv);
 #endif
-#ifdef IO_USE_EPOLL
-	return io_dispatch_epoll(tv);
-#endif
 }