diff options
author | irungentoo <irungentoo@gmail.com> | 2014-07-17 20:44:49 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-07-17 20:44:49 -0400 |
commit | 733c5196011a79ec02851c9d268df4f4181850f3 (patch) | |
tree | 8a8e4dd867185ac0633247e5e41b9b43feea2be1 | |
parent | bcfb1261ac4ab5f6470924f473c8c18bc5f98f01 (diff) |
Build system now automatically enables epoll support in TCP server
when supported.
-rw-r--r-- | configure.ac | 19 | ||||
-rw-r--r-- | m4/ax_have_epoll.m4 | 104 |
2 files changed, 123 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 0dd88da4..174ecbe0 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -200,6 +200,25 @@ AC_ARG_ENABLE([testing], | |||
200 | ] | 200 | ] |
201 | ) | 201 | ) |
202 | 202 | ||
203 | AC_ARG_ENABLE([[epoll]], | ||
204 | [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])], | ||
205 | [enable_epoll=${enableval}], | ||
206 | [enable_epoll='auto'] | ||
207 | ) | ||
208 | |||
209 | if test "$enable_epoll" != "no"; then | ||
210 | AX_HAVE_EPOLL | ||
211 | if test "${ax_cv_have_epoll}" = "yes"; then | ||
212 | AC_DEFINE([TCP_SERVER_USE_EPOLL],[1],[define to 1 to enable epoll support]) | ||
213 | enable_epoll='yes' | ||
214 | else | ||
215 | if test "$enable_epoll" = "yes"; then | ||
216 | AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]]) | ||
217 | fi | ||
218 | enable_epoll='no' | ||
219 | fi | ||
220 | fi | ||
221 | |||
203 | DEPSEARCH= | 222 | DEPSEARCH= |
204 | LIBSODIUM_SEARCH_HEADERS= | 223 | LIBSODIUM_SEARCH_HEADERS= |
205 | LIBSODIUM_SEARCH_LIBS= | 224 | LIBSODIUM_SEARCH_LIBS= |
diff --git a/m4/ax_have_epoll.m4 b/m4/ax_have_epoll.m4 new file mode 100644 index 00000000..07ceb49f --- /dev/null +++ b/m4/ax_have_epoll.m4 | |||
@@ -0,0 +1,104 @@ | |||
1 | # =========================================================================== | ||
2 | # http://www.gnu.org/software/autoconf-archive/ax_have_epoll.html | ||
3 | # =========================================================================== | ||
4 | # | ||
5 | # SYNOPSIS | ||
6 | # | ||
7 | # AX_HAVE_EPOLL([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) | ||
8 | # AX_HAVE_EPOLL_PWAIT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) | ||
9 | # | ||
10 | # DESCRIPTION | ||
11 | # | ||
12 | # This macro determines whether the system supports the epoll I/O event | ||
13 | # interface. A neat usage example would be: | ||
14 | # | ||
15 | # AX_HAVE_EPOLL( | ||
16 | # [AX_CONFIG_FEATURE_ENABLE(epoll)], | ||
17 | # [AX_CONFIG_FEATURE_DISABLE(epoll)]) | ||
18 | # AX_CONFIG_FEATURE( | ||
19 | # [epoll], [This platform supports epoll(7)], | ||
20 | # [HAVE_EPOLL], [This platform supports epoll(7).]) | ||
21 | # | ||
22 | # The epoll interface was added to the Linux kernel in version 2.5.45, and | ||
23 | # the macro verifies that a kernel newer than this is installed. This | ||
24 | # check is somewhat unreliable if <linux/version.h> doesn't match the | ||
25 | # running kernel, but it is necessary regardless, because glibc comes with | ||
26 | # stubs for the epoll_create(), epoll_wait(), etc. that allow programs to | ||
27 | # compile and link even if the kernel is too old; the problem would then | ||
28 | # be detected only at runtime. | ||
29 | # | ||
30 | # Linux kernel version 2.6.19 adds the epoll_pwait() call in addition to | ||
31 | # epoll_wait(). The availability of that function can be tested with the | ||
32 | # second macro. Generally speaking, it is safe to assume that | ||
33 | # AX_HAVE_EPOLL would succeed if AX_HAVE_EPOLL_PWAIT has, but not the | ||
34 | # other way round. | ||
35 | # | ||
36 | # LICENSE | ||
37 | # | ||
38 | # Copyright (c) 2008 Peter Simons <simons@cryp.to> | ||
39 | # | ||
40 | # Copying and distribution of this file, with or without modification, are | ||
41 | # permitted in any medium without royalty provided the copyright notice | ||
42 | # and this notice are preserved. This file is offered as-is, without any | ||
43 | # warranty. | ||
44 | |||
45 | #serial 10 | ||
46 | |||
47 | AC_DEFUN([AX_HAVE_EPOLL], [dnl | ||
48 | ax_have_epoll_cppflags="${CPPFLAGS}" | ||
49 | AC_CHECK_HEADER([linux/version.h], [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) | ||
50 | AC_MSG_CHECKING([for Linux epoll(7) interface]) | ||
51 | AC_CACHE_VAL([ax_cv_have_epoll], [dnl | ||
52 | AC_LINK_IFELSE([dnl | ||
53 | AC_LANG_PROGRAM([dnl | ||
54 | #include <sys/epoll.h> | ||
55 | #ifdef HAVE_LINUX_VERSION_H | ||
56 | # include <linux/version.h> | ||
57 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45) | ||
58 | # error linux kernel version is too old to have epoll | ||
59 | # endif | ||
60 | #endif | ||
61 | ], [dnl | ||
62 | int fd, rc; | ||
63 | struct epoll_event ev; | ||
64 | fd = epoll_create(128); | ||
65 | rc = epoll_wait(fd, &ev, 1, 0);])], | ||
66 | [ax_cv_have_epoll=yes], | ||
67 | [ax_cv_have_epoll=no])]) | ||
68 | CPPFLAGS="${ax_have_epoll_cppflags}" | ||
69 | AS_IF([test "${ax_cv_have_epoll}" = "yes"], | ||
70 | [AC_MSG_RESULT([yes]) | ||
71 | $1],[AC_MSG_RESULT([no]) | ||
72 | $2]) | ||
73 | ])dnl | ||
74 | |||
75 | AC_DEFUN([AX_HAVE_EPOLL_PWAIT], [dnl | ||
76 | ax_have_epoll_cppflags="${CPPFLAGS}" | ||
77 | AC_CHECK_HEADER([linux/version.h], | ||
78 | [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"]) | ||
79 | AC_MSG_CHECKING([for Linux epoll(7) interface with signals extension]) | ||
80 | AC_CACHE_VAL([ax_cv_have_epoll_pwait], [dnl | ||
81 | AC_LINK_IFELSE([dnl | ||
82 | AC_LANG_PROGRAM([dnl | ||
83 | #ifdef HAVE_LINUX_VERSION_H | ||
84 | # include <linux/version.h> | ||
85 | # if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) | ||
86 | # error linux kernel version is too old to have epoll_pwait | ||
87 | # endif | ||
88 | #endif | ||
89 | #include <sys/epoll.h> | ||
90 | #include <signal.h> | ||
91 | ], [dnl | ||
92 | int fd, rc; | ||
93 | struct epoll_event ev; | ||
94 | fd = epoll_create(128); | ||
95 | rc = epoll_wait(fd, &ev, 1, 0); | ||
96 | rc = epoll_pwait(fd, &ev, 1, 0, (sigset_t const *)(0));])], | ||
97 | [ax_cv_have_epoll_pwait=yes], | ||
98 | [ax_cv_have_epoll_pwait=no])]) | ||
99 | CPPFLAGS="${ax_have_epoll_cppflags}" | ||
100 | AS_IF([test "${ax_cv_have_epoll_pwait}" = "yes"], | ||
101 | [AC_MSG_RESULT([yes]) | ||
102 | $1],[AC_MSG_RESULT([no]) | ||
103 | $2]) | ||
104 | ])dnl | ||