select.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* `fd_set' type and related macros, and `select'/`pselect' declarations.
  2. Copyright (C) 1996,97,98,99,2000,01,02,2003 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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h> */
  17. #ifndef _SYS_SELECT_H
  18. #define _SYS_SELECT_H 1
  19. #include <features.h>
  20. /* Get definition of needed basic types. */
  21. #include <bits/types.h>
  22. /* Get __FD_* definitions. */
  23. #include <bits/select.h>
  24. /* Get __sigset_t. */
  25. #include <bits/sigset.h>
  26. #ifndef __sigset_t_defined
  27. # define __sigset_t_defined
  28. typedef __sigset_t sigset_t;
  29. #endif
  30. /* Get definition of timer specification structures. */
  31. #define __need_time_t
  32. #define __need_timespec
  33. #include <time.h>
  34. #define __need_timeval
  35. #include <bits/time.h>
  36. #ifndef __suseconds_t_defined
  37. typedef __suseconds_t suseconds_t;
  38. # define __suseconds_t_defined
  39. #endif
  40. /* The fd_set member is required to be an array of longs. */
  41. typedef long int __fd_mask;
  42. /* Some versions of <linux/posix_types.h> define these macros. */
  43. #undef __NFDBITS
  44. #undef __FDELT
  45. #undef __FDMASK
  46. /* It's easier to assume 8-bit bytes than to get CHAR_BIT. */
  47. #define __NFDBITS (8 * sizeof (__fd_mask))
  48. #define __FDELT(d) ((d) / __NFDBITS)
  49. #define __FDMASK(d) ((__fd_mask) 1 << ((d) % __NFDBITS))
  50. /* fd_set for select and pselect. */
  51. typedef struct
  52. {
  53. /* XPG4.2 requires this member name. Otherwise avoid the name
  54. from the global namespace. */
  55. #ifdef __USE_XOPEN
  56. __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
  57. # define __FDS_BITS(set) ((set)->fds_bits)
  58. #else
  59. __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
  60. # define __FDS_BITS(set) ((set)->__fds_bits)
  61. #endif
  62. } fd_set;
  63. /* Maximum number of file descriptors in `fd_set'. */
  64. #define FD_SETSIZE __FD_SETSIZE
  65. #ifdef __USE_MISC
  66. /* Sometimes the fd_set member is assumed to have this type. */
  67. typedef __fd_mask fd_mask;
  68. /* Number of bits per word of `fd_set' (some code assumes this is 32). */
  69. # define NFDBITS __NFDBITS
  70. #endif
  71. /* Access macros for `fd_set'. */
  72. #define FD_SET(fd, fdsetp) __FD_SET (fd, fdsetp)
  73. #define FD_CLR(fd, fdsetp) __FD_CLR (fd, fdsetp)
  74. #define FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
  75. #define FD_ZERO(fdsetp) __FD_ZERO (fdsetp)
  76. __BEGIN_DECLS
  77. /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
  78. readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
  79. (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out
  80. after waiting the interval specified therein. Returns the number of ready
  81. descriptors, or -1 for errors.
  82. This function is a cancellation point and therefore not marked with
  83. __THROW. */
  84. extern int select (int __nfds, fd_set *__restrict __readfds,
  85. fd_set *__restrict __writefds,
  86. fd_set *__restrict __exceptfds,
  87. struct timeval *__restrict __timeout);
  88. libc_hidden_proto(select)
  89. #ifdef __USE_XOPEN2K
  90. /* Same as above only that the TIMEOUT value is given with higher
  91. resolution and a sigmask which is been set temporarily. This version
  92. should be used.
  93. This function is a cancellation point and therefore not marked with
  94. __THROW. */
  95. extern int pselect (int __nfds, fd_set *__restrict __readfds,
  96. fd_set *__restrict __writefds,
  97. fd_set *__restrict __exceptfds,
  98. const struct timespec *__restrict __timeout,
  99. const __sigset_t *__restrict __sigmask);
  100. #endif
  101. __END_DECLS
  102. #endif /* sys/select.h */