Monday, October 25, 2010

various multiplex methods

今天在编译 bind,遇到了这么个 configure 选项:--enable-epoll。老大们要求将其 enable。于是多看了下。

各个系统上的高效的 multiplex 方法,BSD 有 kqueu,Linux 有 epoll, Solaris 有 /dev/poll。此处 "高效" 是相对传统的 select/poll 说的。

维机百科:
Kqueue is a scalable event notification interface that first appeared in
FreeBSD 4.1
[...]
Some other operating systems which traditionally only supported select(2) and
poll(2) also currently provide more efficient polling alternatives, such as
epoll(7) on Linux and /dev/poll(4) on Solaris.

二 bind 的 configure --help:
--enable-kqueue         use BSD kqueue when available [default=yes]
--enable-epoll          use Linux epoll when available [default=auto]
--enable-devpoll        use /dev/poll when available [default=yes]

三 源代码 bind-version/lib/isc/unix/socket.c:
/*%
 * Choose the most preferable multiplex method.
 */
#ifdef ISC_PLATFORM_HAVEKQUEUE
#define USE_KQUEUE
#elif defined (ISC_PLATFORM_HAVEEPOLL)
#define USE_EPOLL
#elif defined (ISC_PLATFORM_HAVEDEVPOLL)
#define USE_DEVPOLL
typedef struct {
        unsigned int want_read : 1, 
                want_write : 1; 
} pollinfo_t;
#else
#define USE_SELECT
#endif  /* ISC_PLATFORM_HAVEKQUEUE */