select.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef _SYS_SELECT_H
  2. #define _SYS_SELECT_H
  3. /* We don't define fd_set and friends if we are compiling POSIX
  4. source, or if we have included (or may include as indicated
  5. by __USE_W32_SOCKETS) the W32api winsock[2].h header which
  6. defines Windows versions of them. Note that a program which
  7. includes the W32api winsock[2].h header must know what it is doing;
  8. it must not call the Cygwin select function.
  9. */
  10. # if !(defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS))
  11. #include <sys/cdefs.h>
  12. #include <sys/_sigset.h>
  13. #include <sys/_timeval.h>
  14. #include <sys/timespec.h>
  15. #if !defined(_SIGSET_T_DECLARED)
  16. #define _SIGSET_T_DECLARED
  17. typedef __sigset_t sigset_t;
  18. #endif
  19. # define _SYS_TYPES_FD_SET
  20. /*
  21. * Select uses bit masks of file descriptors in longs.
  22. * These macros manipulate such bit fields (the filesystem macros use chars).
  23. * FD_SETSIZE may be defined by the user, but the default here
  24. * should be >= NOFILE (param.h).
  25. */
  26. #ifndef FD_SETSIZE
  27. #define FD_SETSIZE 64
  28. #endif
  29. typedef unsigned long __fd_mask;
  30. #if __BSD_VISIBLE
  31. typedef __fd_mask fd_mask;
  32. #endif
  33. #define _NFDBITS ((int)sizeof(__fd_mask) * 8) /* bits per mask */
  34. #if __BSD_VISIBLE
  35. #define NFDBITS _NFDBITS
  36. #endif
  37. #ifndef _howmany
  38. #define _howmany(x,y) (((x) + ((y) - 1)) / (y))
  39. #endif
  40. typedef struct fd_set {
  41. __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
  42. } fd_set;
  43. #if __BSD_VISIBLE
  44. #define fds_bits __fds_bits
  45. #endif
  46. #define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS))
  47. #define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
  48. #if __BSD_VISIBLE
  49. #define FD_COPY(f, t) (void)(*(t) = *(f))
  50. #endif
  51. #define FD_ISSET(n, p) (((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0)
  52. #define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
  53. #define FD_ZERO(p) do { \
  54. fd_set *_p; \
  55. __size_t _n; \
  56. \
  57. _p = (p); \
  58. _n = _howmany(FD_SETSIZE, _NFDBITS); \
  59. while (_n > 0) \
  60. _p->__fds_bits[--_n] = 0; \
  61. } while (0)
  62. #if !defined (__INSIDE_CYGWIN_NET__)
  63. __BEGIN_DECLS
  64. int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
  65. fd_set *__exceptfds, struct timeval *__timeout));
  66. #if __POSIX_VISIBLE >= 200112
  67. int pselect __P ((int __n, fd_set *__readfds, fd_set *__writefds,
  68. fd_set *__exceptfds, const struct timespec *__timeout,
  69. const sigset_t *__set));
  70. #endif
  71. __END_DECLS
  72. #endif /* !__INSIDE_CYGWIN_NET__ */
  73. #endif /* !(_WINSOCK_H || _WINSOCKAPI_ || __USE_W32_SOCKETS) */
  74. #endif /* sys/select.h */