sys_select.in.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* Substitute for <sys/select.h>.
  2. Copyright (C) 2007-2013 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>. */
  13. # if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. # endif
  16. @PRAGMA_COLUMNS@
  17. /* On OSF/1 and Solaris 2.6, <sys/types.h> and <sys/time.h>
  18. both include <sys/select.h>.
  19. Simply delegate to the system's header in this case. */
  20. #if (@HAVE_SYS_SELECT_H@ \
  21. && ((defined __osf__ && defined _SYS_TYPES_H_ && defined _OSF_SOURCE) \
  22. || (defined __sun && defined _SYS_TYPES_H \
  23. && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
  24. || defined __EXTENSIONS__))) \
  25. && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H)
  26. # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
  27. # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
  28. #elif (@HAVE_SYS_SELECT_H@ \
  29. && ((defined __osf__ && defined _SYS_TIME_H_ && defined _OSF_SOURCE) \
  30. || (defined __sun && defined _SYS_TIME_H \
  31. && (! (defined _XOPEN_SOURCE || defined _POSIX_C_SOURCE) \
  32. || defined __EXTENSIONS__))) \
  33. && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H)
  34. # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
  35. # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
  36. /* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
  37. <sys/bsd_types.h>, which includes <sys/select.h>. At this point we cannot
  38. include <signal.h>, because that includes <internal/signal_core.h>, which
  39. gives a syntax error because <sys/timespec.h> has not been completely
  40. processed. Simply delegate to the system's header in this case. */
  41. #elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
  42. # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
  43. # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
  44. /* On OpenBSD 5.0, <pthread.h> includes <sys/types.h>, which includes
  45. <sys/select.h>. At this point we cannot include <signal.h>, because that
  46. includes gnulib's pthread.h override, which gives a syntax error because
  47. /usr/include/pthread.h has not been completely processed. Simply delegate
  48. to the system's header in this case. */
  49. #elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && !defined PTHREAD_MUTEX_INITIALIZER)
  50. # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
  51. #else
  52. #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
  53. /* On many platforms, <sys/select.h> assumes prior inclusion of
  54. <sys/types.h>. Also, mingw defines sigset_t there, instead of
  55. in <signal.h> where it belongs. */
  56. #include <sys/types.h>
  57. #if @HAVE_SYS_SELECT_H@
  58. /* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
  59. of 'struct timeval', and no definition of this type.
  60. Also, Mac OS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
  61. in <sys/time.h>.
  62. But avoid namespace pollution on glibc systems. */
  63. # ifndef __GLIBC__
  64. # include <sys/time.h>
  65. # endif
  66. /* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
  67. that relies on memset(), but without including <string.h>.
  68. But in any case avoid namespace pollution on glibc systems. */
  69. # if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ || defined __BEOS__) \
  70. && ! defined __GLIBC__
  71. # include <string.h>
  72. # endif
  73. /* The include_next requires a split double-inclusion guard. */
  74. # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
  75. #endif
  76. /* Get definition of 'sigset_t'.
  77. But avoid namespace pollution on glibc systems.
  78. Do this after the include_next (for the sake of OpenBSD 5.0) but before
  79. the split double-inclusion guard (for the sake of Solaris). */
  80. #if !(defined __GLIBC__ && !defined __UCLIBC__)
  81. # include <signal.h>
  82. #endif
  83. #ifndef _@GUARD_PREFIX@_SYS_SELECT_H
  84. #define _@GUARD_PREFIX@_SYS_SELECT_H
  85. #if !@HAVE_SYS_SELECT_H@
  86. /* A platform that lacks <sys/select.h>. */
  87. /* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
  88. on most platforms. */
  89. # include <sys/time.h>
  90. /* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
  91. that relies on memset(), but without including <string.h>. */
  92. # if defined __hpux
  93. # include <string.h>
  94. # endif
  95. /* On native Windows platforms:
  96. Get the 'fd_set' type.
  97. Get the close() declaration before we override it. */
  98. # if @HAVE_WINSOCK2_H@
  99. # if !defined _GL_INCLUDING_WINSOCK2_H
  100. # define _GL_INCLUDING_WINSOCK2_H
  101. # include <winsock2.h>
  102. # undef _GL_INCLUDING_WINSOCK2_H
  103. # endif
  104. # include <io.h>
  105. # endif
  106. #endif
  107. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  108. /* The definition of _GL_WARN_ON_USE is copied here. */
  109. /* Fix some definitions from <winsock2.h>. */
  110. #if @HAVE_WINSOCK2_H@
  111. # if !GNULIB_defined_rpl_fd_isset
  112. /* Re-define FD_ISSET to avoid a WSA call while we are not using
  113. network sockets. */
  114. static int
  115. rpl_fd_isset (SOCKET fd, fd_set * set)
  116. {
  117. u_int i;
  118. if (set == NULL)
  119. return 0;
  120. for (i = 0; i < set->fd_count; i++)
  121. if (set->fd_array[i] == fd)
  122. return 1;
  123. return 0;
  124. }
  125. # define GNULIB_defined_rpl_fd_isset 1
  126. # endif
  127. # undef FD_ISSET
  128. # define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
  129. #endif
  130. /* Hide some function declarations from <winsock2.h>. */
  131. #if @HAVE_WINSOCK2_H@
  132. # if !defined _@GUARD_PREFIX@_UNISTD_H
  133. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  134. # undef close
  135. # define close close_used_without_including_unistd_h
  136. # else
  137. _GL_WARN_ON_USE (close,
  138. "close() used without including <unistd.h>");
  139. # endif
  140. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  141. # undef gethostname
  142. # define gethostname gethostname_used_without_including_unistd_h
  143. # else
  144. _GL_WARN_ON_USE (gethostname,
  145. "gethostname() used without including <unistd.h>");
  146. # endif
  147. # endif
  148. # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
  149. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  150. # undef socket
  151. # define socket socket_used_without_including_sys_socket_h
  152. # undef connect
  153. # define connect connect_used_without_including_sys_socket_h
  154. # undef accept
  155. # define accept accept_used_without_including_sys_socket_h
  156. # undef bind
  157. # define bind bind_used_without_including_sys_socket_h
  158. # undef getpeername
  159. # define getpeername getpeername_used_without_including_sys_socket_h
  160. # undef getsockname
  161. # define getsockname getsockname_used_without_including_sys_socket_h
  162. # undef getsockopt
  163. # define getsockopt getsockopt_used_without_including_sys_socket_h
  164. # undef listen
  165. # define listen listen_used_without_including_sys_socket_h
  166. # undef recv
  167. # define recv recv_used_without_including_sys_socket_h
  168. # undef send
  169. # define send send_used_without_including_sys_socket_h
  170. # undef recvfrom
  171. # define recvfrom recvfrom_used_without_including_sys_socket_h
  172. # undef sendto
  173. # define sendto sendto_used_without_including_sys_socket_h
  174. # undef setsockopt
  175. # define setsockopt setsockopt_used_without_including_sys_socket_h
  176. # undef shutdown
  177. # define shutdown shutdown_used_without_including_sys_socket_h
  178. # else
  179. _GL_WARN_ON_USE (socket,
  180. "socket() used without including <sys/socket.h>");
  181. _GL_WARN_ON_USE (connect,
  182. "connect() used without including <sys/socket.h>");
  183. _GL_WARN_ON_USE (accept,
  184. "accept() used without including <sys/socket.h>");
  185. _GL_WARN_ON_USE (bind,
  186. "bind() used without including <sys/socket.h>");
  187. _GL_WARN_ON_USE (getpeername,
  188. "getpeername() used without including <sys/socket.h>");
  189. _GL_WARN_ON_USE (getsockname,
  190. "getsockname() used without including <sys/socket.h>");
  191. _GL_WARN_ON_USE (getsockopt,
  192. "getsockopt() used without including <sys/socket.h>");
  193. _GL_WARN_ON_USE (listen,
  194. "listen() used without including <sys/socket.h>");
  195. _GL_WARN_ON_USE (recv,
  196. "recv() used without including <sys/socket.h>");
  197. _GL_WARN_ON_USE (send,
  198. "send() used without including <sys/socket.h>");
  199. _GL_WARN_ON_USE (recvfrom,
  200. "recvfrom() used without including <sys/socket.h>");
  201. _GL_WARN_ON_USE (sendto,
  202. "sendto() used without including <sys/socket.h>");
  203. _GL_WARN_ON_USE (setsockopt,
  204. "setsockopt() used without including <sys/socket.h>");
  205. _GL_WARN_ON_USE (shutdown,
  206. "shutdown() used without including <sys/socket.h>");
  207. # endif
  208. # endif
  209. #endif
  210. #if @GNULIB_PSELECT@
  211. # if @REPLACE_PSELECT@
  212. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  213. # undef pselect
  214. # define pselect rpl_pselect
  215. # endif
  216. _GL_FUNCDECL_RPL (pselect, int,
  217. (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
  218. struct timespec const *restrict, const sigset_t *restrict));
  219. _GL_CXXALIAS_RPL (pselect, int,
  220. (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
  221. struct timespec const *restrict, const sigset_t *restrict));
  222. # else
  223. # if !@HAVE_PSELECT@
  224. _GL_FUNCDECL_SYS (pselect, int,
  225. (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
  226. struct timespec const *restrict, const sigset_t *restrict));
  227. # endif
  228. _GL_CXXALIAS_SYS (pselect, int,
  229. (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
  230. struct timespec const *restrict, const sigset_t *restrict));
  231. # endif
  232. _GL_CXXALIASWARN (pselect);
  233. #elif defined GNULIB_POSIXCHECK
  234. # undef pselect
  235. # if HAVE_RAW_DECL_PSELECT
  236. _GL_WARN_ON_USE (pselect, "pselect is not portable - "
  237. "use gnulib module pselect for portability");
  238. # endif
  239. #endif
  240. #if @GNULIB_SELECT@
  241. # if @REPLACE_SELECT@
  242. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  243. # undef select
  244. # define select rpl_select
  245. # endif
  246. _GL_FUNCDECL_RPL (select, int,
  247. (int, fd_set *, fd_set *, fd_set *, struct timeval *));
  248. _GL_CXXALIAS_RPL (select, int,
  249. (int, fd_set *, fd_set *, fd_set *, struct timeval *));
  250. # else
  251. _GL_CXXALIAS_SYS (select, int,
  252. (int, fd_set *, fd_set *, fd_set *, struct timeval *));
  253. # endif
  254. _GL_CXXALIASWARN (select);
  255. #elif @HAVE_WINSOCK2_H@
  256. # undef select
  257. # define select select_used_without_requesting_gnulib_module_select
  258. #elif defined GNULIB_POSIXCHECK
  259. # undef select
  260. # if HAVE_RAW_DECL_SELECT
  261. _GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
  262. "use gnulib module select for portability");
  263. # endif
  264. #endif
  265. #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
  266. #endif /* _@GUARD_PREFIX@_SYS_SELECT_H */
  267. #endif /* OSF/1 */