ax_have_epoll.m4 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # ===========================================================================
  2. # https://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. #serial 11
  45. AC_DEFUN([AX_HAVE_EPOLL], [dnl
  46. ax_have_epoll_cppflags="${CPPFLAGS}"
  47. AC_CHECK_HEADER([linux/version.h], [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"])
  48. AC_MSG_CHECKING([for Linux epoll(7) interface])
  49. AC_CACHE_VAL([ax_cv_have_epoll], [dnl
  50. AC_LINK_IFELSE([dnl
  51. AC_LANG_PROGRAM([dnl
  52. #include <sys/epoll.h>
  53. #ifdef HAVE_LINUX_VERSION_H
  54. # include <linux/version.h>
  55. # if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,45)
  56. # error linux kernel version is too old to have epoll
  57. # endif
  58. #endif
  59. ], [dnl
  60. int fd, rc;
  61. struct epoll_event ev;
  62. fd = epoll_create(128);
  63. rc = epoll_wait(fd, &ev, 1, 0);])],
  64. [ax_cv_have_epoll=yes],
  65. [ax_cv_have_epoll=no])])
  66. CPPFLAGS="${ax_have_epoll_cppflags}"
  67. AS_IF([test "${ax_cv_have_epoll}" = "yes"],
  68. [AC_MSG_RESULT([yes])
  69. $1],[AC_MSG_RESULT([no])
  70. $2])
  71. ])dnl
  72. AC_DEFUN([AX_HAVE_EPOLL_PWAIT], [dnl
  73. ax_have_epoll_cppflags="${CPPFLAGS}"
  74. AC_CHECK_HEADER([linux/version.h],
  75. [CPPFLAGS="${CPPFLAGS} -DHAVE_LINUX_VERSION_H"])
  76. AC_MSG_CHECKING([for Linux epoll(7) interface with signals extension])
  77. AC_CACHE_VAL([ax_cv_have_epoll_pwait], [dnl
  78. AC_LINK_IFELSE([dnl
  79. AC_LANG_PROGRAM([dnl
  80. #ifdef HAVE_LINUX_VERSION_H
  81. # include <linux/version.h>
  82. # if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
  83. # error linux kernel version is too old to have epoll_pwait
  84. # endif
  85. #endif
  86. #include <sys/epoll.h>
  87. #include <signal.h>
  88. ], [dnl
  89. int fd, rc;
  90. struct epoll_event ev;
  91. fd = epoll_create(128);
  92. rc = epoll_wait(fd, &ev, 1, 0);
  93. rc = epoll_pwait(fd, &ev, 1, 0, (sigset_t const *)(0));])],
  94. [ax_cv_have_epoll_pwait=yes],
  95. [ax_cv_have_epoll_pwait=no])])
  96. CPPFLAGS="${ax_have_epoll_cppflags}"
  97. AS_IF([test "${ax_cv_have_epoll_pwait}" = "yes"],
  98. [AC_MSG_RESULT([yes])
  99. $1],[AC_MSG_RESULT([no])
  100. $2])
  101. ])dnl