geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

119 lines
2.9 KiB

  1. include(CheckCSourceCompiles)
  2. # - check_nonblocking_socket_support()
  3. #
  4. # Check for how to set a socket to non-blocking state. There seems to exist
  5. # four known different ways, with the one used almost everywhere being POSIX
  6. # and XPG3, while the other different ways for different systems (old BSD,
  7. # Windows and Amiga).
  8. #
  9. # One of the following variables will be set indicating the supported
  10. # method (if any):
  11. # HAVE_O_NONBLOCK
  12. # HAVE_FIONBIO
  13. # HAVE_IOCTLSOCKET
  14. # HAVE_IOCTLSOCKET_CASE
  15. # HAVE_SO_NONBLOCK
  16. # HAVE_DISABLED_NONBLOCKING
  17. #
  18. # The following variables may be set before calling this macro to
  19. # modify the way the check is run:
  20. #
  21. # CMAKE_REQUIRED_FLAGS = string of compile command line flags
  22. # CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
  23. # CMAKE_REQUIRED_INCLUDES = list of include directories
  24. # CMAKE_REQUIRED_LIBRARIES = list of libraries to link
  25. #
  26. macro(check_nonblocking_socket_support)
  27. # There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
  28. # O_NONBLOCK define is found but does not work.
  29. check_c_source_compiles("
  30. #include <sys/types.h>
  31. #include <unistd.h>
  32. #include <fcntl.h>
  33. #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  34. # if defined(__SVR4) || defined(__srv4__)
  35. # define PLATFORM_SOLARIS
  36. # else
  37. # define PLATFORM_SUNOS4
  38. # endif
  39. #endif
  40. #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
  41. # define PLATFORM_AIX_V3
  42. #endif
  43. #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
  44. #error \"O_NONBLOCK does not work on this platform\"
  45. #endif
  46. int main()
  47. {
  48. int socket;
  49. int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
  50. }"
  51. HAVE_O_NONBLOCK)
  52. if(NOT HAVE_O_NONBLOCK)
  53. check_c_source_compiles("/* FIONBIO test (old-style unix) */
  54. #include <unistd.h>
  55. #include <stropts.h>
  56. int main()
  57. {
  58. int socket;
  59. int flags = ioctl(socket, FIONBIO, &flags);
  60. }"
  61. HAVE_FIONBIO)
  62. if(NOT HAVE_FIONBIO)
  63. check_c_source_compiles("/* ioctlsocket test (Windows) */
  64. #undef inline
  65. #ifndef WIN32_LEAN_AND_MEAN
  66. #define WIN32_LEAN_AND_MEAN
  67. #endif
  68. #include <windows.h>
  69. #include <winsock2.h>
  70. int main()
  71. {
  72. SOCKET sd;
  73. unsigned long flags = 0;
  74. sd = socket(0, 0, 0);
  75. ioctlsocket(sd, FIONBIO, &flags);
  76. }"
  77. HAVE_IOCTLSOCKET)
  78. if(NOT HAVE_IOCTLSOCKET)
  79. check_c_source_compiles("/* IoctlSocket test (Amiga?) */
  80. #include <sys/ioctl.h>
  81. int main()
  82. {
  83. int socket;
  84. int flags = IoctlSocket(socket, FIONBIO, (long)1);
  85. }"
  86. HAVE_IOCTLSOCKET_CASE)
  87. if(NOT HAVE_IOCTLSOCKET_CASE)
  88. check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */
  89. #include <socket.h>
  90. int main()
  91. {
  92. long b = 1;
  93. int socket;
  94. int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
  95. }"
  96. HAVE_SO_NONBLOCK)
  97. if(NOT HAVE_SO_NONBLOCK)
  98. # No non-blocking socket method found
  99. set(HAVE_DISABLED_NONBLOCKING 1)
  100. endif()
  101. endif()
  102. endif()
  103. endif()
  104. endif()
  105. endmacro()