Debian Codegraph @

cmake/CheckNonblockingSocketSupport.cmake

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