select.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* `fd_set' type and related macros, and `select'/`pselect' declarations.
  2. Copyright (C) 1996-2021 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h> */
  16. #ifndef _SYS_SELECT_H
  17. #define _SYS_SELECT_H 1
  18. #include <features.h>
  19. /* Get definition of needed basic types. */
  20. #include <bits/types.h>
  21. /* Get __FD_* definitions. */
  22. #include <bits/select.h>
  23. /* Get sigset_t. */
  24. #include <bits/types/sigset_t.h>
  25. /* Get definition of timer specification structures. */
  26. #include <bits/types/time_t.h>
  27. #include <bits/types/struct_timeval.h>
  28. #ifdef __USE_XOPEN2K
  29. # include <bits/types/struct_timespec.h>
  30. #endif
  31. #ifndef __suseconds_t_defined
  32. typedef __suseconds_t suseconds_t;
  33. # define __suseconds_t_defined
  34. #endif
  35. /* The fd_set member is required to be an array of longs. */
  36. typedef long int __fd_mask;
  37. /* Some versions of <linux/posix_types.h> define this macros. */
  38. #undef __NFDBITS
  39. /* It's easier to assume 8-bit bytes than to get CHAR_BIT. */
  40. #define __NFDBITS (8 * (int) sizeof (__fd_mask))
  41. #define __FD_ELT(d) ((d) / __NFDBITS)
  42. #define __FD_MASK(d) ((__fd_mask) (1UL << ((d) % __NFDBITS)))
  43. /* fd_set for select and pselect. */
  44. typedef struct
  45. {
  46. /* XPG4.2 requires this member name. Otherwise avoid the name
  47. from the global namespace. */
  48. #ifdef __USE_XOPEN
  49. __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
  50. # define __FDS_BITS(set) ((set)->fds_bits)
  51. #else
  52. __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
  53. # define __FDS_BITS(set) ((set)->__fds_bits)
  54. #endif
  55. } fd_set;
  56. /* Maximum number of file descriptors in `fd_set'. */
  57. #define FD_SETSIZE __FD_SETSIZE
  58. #ifdef __USE_MISC
  59. /* Sometimes the fd_set member is assumed to have this type. */
  60. typedef __fd_mask fd_mask;
  61. /* Number of bits per word of `fd_set' (some code assumes this is 32). */
  62. # define NFDBITS __NFDBITS
  63. #endif
  64. /* Access macros for `fd_set'. */
  65. #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
  66. #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
  67. #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
  68. #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
  69. __BEGIN_DECLS
  70. /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
  71. readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
  72. (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
  73. after waiting the interval specified therein. Returns the number of ready
  74. descriptors, or -1 for errors.
  75. This function is a cancellation point and therefore not marked with
  76. __THROW. */
  77. extern int select (int __nfds, fd_set *__restrict __readfds,
  78. fd_set *__restrict __writefds,
  79. fd_set *__restrict __exceptfds,
  80. struct timeval *__restrict __timeout);
  81. #ifdef __USE_XOPEN2K
  82. /* Same as above only that the TIMEOUT value is given with higher
  83. resolution and a sigmask which is been set temporarily. This version
  84. should be used.
  85. This function is a cancellation point and therefore not marked with
  86. __THROW. */
  87. extern int pselect (int __nfds, fd_set *__restrict __readfds,
  88. fd_set *__restrict __writefds,
  89. fd_set *__restrict __exceptfds,
  90. const struct timespec *__restrict __timeout,
  91. const __sigset_t *__restrict __sigmask);
  92. #endif
  93. /* Define some inlines helping to catch common problems. */
  94. #if __USE_FORTIFY_LEVEL > 0 && defined __GNUC__
  95. # include <bits/select2.h>
  96. #endif
  97. __END_DECLS
  98. #endif /* sys/select.h */