1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <grpc/support/port_platform.h>
20 
21 #ifndef GRPC_CORE_LIB_IOMGR_PORT_H
22 #define GRPC_CORE_LIB_IOMGR_PORT_H
23 
24 #ifdef GRPC_UV
25 #ifndef GRPC_CUSTOM_SOCKET
26 #define GRPC_CUSTOM_SOCKET
27 #endif
28 #endif
29 #if defined(GRPC_CUSTOM_SOCKET)
30 // Do Nothing
31 #elif defined(GPR_MANYLINUX1)
32 #define GRPC_HAVE_ARPA_NAMESER 1
33 #define GRPC_HAVE_IFADDRS 1
34 #define GRPC_HAVE_IPV6_RECVPKTINFO 1
35 #define GRPC_HAVE_IP_PKTINFO 1
36 #define GRPC_HAVE_MSG_NOSIGNAL 1
37 #define GRPC_HAVE_UNIX_SOCKET 1
38 #define GRPC_POSIX_FORK 1
39 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
40 #define GRPC_POSIX_SOCKET 1
41 #define GRPC_POSIX_SOCKETUTILS 1
42 #define GRPC_POSIX_WAKEUP_FD 1
43 #define GRPC_LINUX_EPOLL 1
44 #elif defined(GPR_WINDOWS)
45 #define GRPC_WINSOCK_SOCKET 1
46 #define GRPC_WINDOWS_SOCKETUTILS 1
47 #elif defined(GPR_ANDROID)
48 #define GRPC_HAVE_IPV6_RECVPKTINFO 1
49 #define GRPC_HAVE_IP_PKTINFO 1
50 #define GRPC_HAVE_MSG_NOSIGNAL 1
51 #define GRPC_HAVE_UNIX_SOCKET 1
52 #define GRPC_LINUX_EVENTFD 1
53 #define GRPC_POSIX_SOCKET 1
54 #define GRPC_POSIX_SOCKETUTILS 1
55 #define GRPC_POSIX_WAKEUP_FD 1
56 #elif defined(GPR_LINUX)
57 #define GRPC_HAVE_ARPA_NAMESER 1
58 #define GRPC_HAVE_IFADDRS 1
59 #define GRPC_HAVE_IPV6_RECVPKTINFO 1
60 #define GRPC_HAVE_IP_PKTINFO 1
61 #define GRPC_HAVE_MSG_NOSIGNAL 1
62 #define GRPC_HAVE_UNIX_SOCKET 1
63 #ifdef LINUX_VERSION_CODE
64 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
65 #define GRPC_LINUX_ERRQUEUE 1
66 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0) */
67 #endif /* LINUX_VERSION_CODE */
68 #define GRPC_LINUX_MULTIPOLL_WITH_EPOLL 1
69 #define GRPC_POSIX_FORK 1
70 #define GRPC_POSIX_HOST_NAME_MAX 1
71 #define GRPC_POSIX_SOCKET 1
72 #define GRPC_POSIX_WAKEUP_FD 1
73 #ifdef __GLIBC_PREREQ
74 #if __GLIBC_PREREQ(2, 4)
75 #define GRPC_LINUX_EPOLL 1
76 #endif
77 #if __GLIBC_PREREQ(2, 9)
78 #define GRPC_LINUX_EPOLL_CREATE1 1
79 #define GRPC_LINUX_EVENTFD 1
80 #endif
81 #if __GLIBC_PREREQ(2, 10)
82 #define GRPC_LINUX_SOCKETUTILS 1
83 #endif
84 #endif
85 #ifdef LINUX_VERSION_CODE
86 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
87 #define GRPC_HAVE_TCP_USER_TIMEOUT
88 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37) */
89 #endif /* LINUX_VERSION_CODE */
90 #ifndef __GLIBC__
91 #define GRPC_LINUX_EPOLL 1
92 #define GRPC_LINUX_EPOLL_CREATE1 1
93 #define GRPC_LINUX_EVENTFD 1
94 #define GRPC_MSG_IOVLEN_TYPE int
95 #endif
96 #ifndef GRPC_LINUX_EVENTFD
97 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
98 #endif
99 #ifndef GRPC_LINUX_SOCKETUTILS
100 #define GRPC_POSIX_SOCKETUTILS
101 #endif
102 #elif defined(GPR_APPLE)
103 #define GRPC_HAVE_ARPA_NAMESER 1
104 #define GRPC_HAVE_IFADDRS 1
105 #define GRPC_HAVE_SO_NOSIGPIPE 1
106 #define GRPC_HAVE_UNIX_SOCKET 1
107 #define GRPC_MSG_IOVLEN_TYPE int
108 #define GRPC_POSIX_FORK 1
109 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
110 #ifdef GRPC_CFSTREAM
111 #define GRPC_CFSTREAM_IOMGR 1
112 #define GRPC_CFSTREAM_CLIENT 1
113 #define GRPC_CFSTREAM_ENDPOINT 1
114 #define GRPC_POSIX_SOCKET_ARES_EV_DRIVER 1
115 #define GRPC_POSIX_SOCKET_EV 1
116 #define GRPC_POSIX_SOCKET_EV_EPOLL1 1
117 #define GRPC_POSIX_SOCKET_EV_EPOLLEX 1
118 #define GRPC_POSIX_SOCKET_EV_EPOLLSIG 1
119 #define GRPC_POSIX_SOCKET_EV_POLL 1
120 #define GRPC_POSIX_SOCKET_RESOLVE_ADDRESS 1
121 #define GRPC_POSIX_SOCKET_SOCKADDR 1
122 #define GRPC_POSIX_SOCKET_SOCKET_FACTORY 1
123 #define GRPC_POSIX_SOCKET_TCP 1
124 #define GRPC_POSIX_SOCKET_TCP_CLIENT 1
125 #define GRPC_POSIX_SOCKET_TCP_SERVER 1
126 #define GRPC_POSIX_SOCKET_TCP_SERVER_UTILS_COMMON 1
127 #define GRPC_POSIX_SOCKET_UTILS_COMMON 1
128 #else
129 #define GRPC_POSIX_SOCKET 1
130 #endif
131 #define GRPC_POSIX_SOCKETUTILS 1
132 #define GRPC_POSIX_SYSCONF 1
133 #define GRPC_POSIX_WAKEUP_FD 1
134 #elif defined(GPR_FREEBSD)
135 #define GRPC_HAVE_ARPA_NAMESER 1
136 #define GRPC_HAVE_IFADDRS 1
137 #define GRPC_HAVE_IPV6_RECVPKTINFO 1
138 #define GRPC_HAVE_SO_NOSIGPIPE 1
139 #define GRPC_HAVE_UNIX_SOCKET 1
140 #define GRPC_POSIX_FORK 1
141 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
142 #define GRPC_POSIX_SOCKET 1
143 #define GRPC_POSIX_SOCKETUTILS 1
144 #define GRPC_POSIX_WAKEUP_FD 1
145 #elif defined(GPR_OPENBSD)
146 #define GRPC_HAVE_IFADDRS 1
147 #define GRPC_HAVE_IPV6_RECVPKTINFO 1
148 #define GRPC_HAVE_UNIX_SOCKET 1
149 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
150 #define GRPC_POSIX_SOCKET 1
151 #define GRPC_POSIX_SOCKETUTILS 1
152 #define GRPC_POSIX_WAKEUP_FD 1
153 #elif defined(GPR_SOLARIS)
154 #define GRPC_HAVE_UNIX_SOCKET 1
155 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
156 #define GRPC_POSIX_SOCKET 1
157 #define GRPC_POSIX_SOCKETUTILS 1
158 #define GRPC_POSIX_WAKEUP_FD 1
159 #elif defined(GPR_AIX)
160 #define GRPC_HAVE_UNIX_SOCKET 1
161 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
162 #define GRPC_POSIX_SOCKET 1
163 #define GRPC_POSIX_SOCKETUTILS 1
164 #define GRPC_POSIX_WAKEUP_FD 1
165 #elif defined(GPR_NACL)
166 #define GRPC_HAVE_ARPA_NAMESER 1
167 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
168 #define GRPC_POSIX_SOCKET 1
169 #define GRPC_POSIX_SOCKETUTILS 1
170 #define GRPC_POSIX_WAKEUP_FD 1
171 #elif !defined(GPR_NO_AUTODETECT_PLATFORM)
172 #error "Platform not recognized"
173 #endif
174 
175 #if defined(GRPC_POSIX_SOCKET) + defined(GRPC_WINSOCK_SOCKET) + \
176         defined(GRPC_CUSTOM_SOCKET) + defined(GRPC_CFSTREAM) != \
177     1
178 #error \
179     "Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GRPC_CUSTOM_SOCKET"
180 #endif
181 
182 #ifdef GRPC_POSIX_SOCKET
183 #define GRPC_POSIX_SOCKET_ARES_EV_DRIVER 1
184 #define GRPC_POSIX_SOCKET_EV 1
185 #define GRPC_POSIX_SOCKET_EV_EPOLLEX 1
186 #define GRPC_POSIX_SOCKET_EV_EPOLLSIG 1
187 #define GRPC_POSIX_SOCKET_EV_POLL 1
188 #define GRPC_POSIX_SOCKET_EV_EPOLL1 1
189 #define GRPC_POSIX_SOCKET_IOMGR 1
190 #define GRPC_POSIX_SOCKET_RESOLVE_ADDRESS 1
191 #define GRPC_POSIX_SOCKET_SOCKADDR 1
192 #define GRPC_POSIX_SOCKET_SOCKET_FACTORY 1
193 #define GRPC_POSIX_SOCKET_TCP 1
194 #define GRPC_POSIX_SOCKET_TCP_CLIENT 1
195 #define GRPC_POSIX_SOCKET_TCP_SERVER 1
196 #define GRPC_POSIX_SOCKET_TCP_SERVER_UTILS_COMMON 1
197 #define GRPC_POSIX_SOCKET_UTILS_COMMON 1
198 #endif
199 
200 #if defined(GRPC_POSIX_HOST_NAME_MAX) && defined(GRPC_POSIX_SYSCONF)
201 #error "Cannot define both GRPC_POSIX_HOST_NAME_MAX and GRPC_POSIX_SYSCONF"
202 #endif
203 #if !defined(GRPC_POSIX_HOST_NAME_MAX) && !defined(GRPC_POSIX_SYSCONF)
204 #define GRPC_GETHOSTNAME_FALLBACK 1
205 #endif
206 
207 #endif /* GRPC_CORE_LIB_IOMGR_PORT_H */
208