Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* select.h
  2.    Copyright 1998, 1999, 2000, 2001, 2005, 2009 Red Hat, Inc.
  3.  
  4.    Written by Geoffrey Noer <noer@cygnus.com>
  5.  
  6. This file is part of Cygwin.
  7.  
  8. This software is a copyrighted work licensed under the terms of the
  9. Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
  10. details. */
  11.  
  12. #ifndef _SYS_SELECT_H
  13. #define _SYS_SELECT_H
  14.  
  15. /* We don't define fd_set and friends if we are compiling POSIX
  16.    source, or if we have included (or may include as indicated
  17.    by __USE_W32_SOCKETS) the W32api winsock[2].h header which
  18.    defines Windows versions of them.   Note that a program which
  19.    includes the W32api winsock[2].h header must know what it is doing;
  20.    it must not call the Cygwin select function.
  21. */
  22. # if !(defined (_POSIX_SOURCE) || defined (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS))
  23.  
  24. #include <sys/cdefs.h>
  25.  
  26. #include <sys/_sigset.h>
  27. #include <sys/_timeval.h>
  28. #include <sys/timespec.h>
  29.  
  30. #if !defined(_SIGSET_T_DECLARED)
  31. #define _SIGSET_T_DECLARED
  32. typedef __sigset_t      sigset_t;
  33. #endif
  34.  
  35. #  define _SYS_TYPES_FD_SET
  36. /*
  37.  * Select uses bit masks of file descriptors in longs.
  38.  * These macros manipulate such bit fields (the filesystem macros use chars).
  39.  * FD_SETSIZE may be defined by the user, but the default here
  40.  * should be >= NOFILE (param.h).
  41.  */
  42. #  ifndef       FD_SETSIZE
  43. #       define  FD_SETSIZE      64
  44. #  endif
  45.  
  46. typedef unsigned long   fd_mask;
  47. #  define       NFDBITS (sizeof (fd_mask) * 8)  /* bits per mask */
  48. #  ifndef       _howmany
  49. #       define  _howmany(x,y)   (((x)+((y)-1))/(y))
  50. #  endif
  51.  
  52. /* We use a macro for fd_set so that including Sockets.h afterwards
  53.    can work.  */
  54. typedef struct _types_fd_set {
  55.         fd_mask fds_bits[_howmany(FD_SETSIZE, NFDBITS)];
  56. } _types_fd_set;
  57.  
  58. #define fd_set _types_fd_set
  59.  
  60. #  define       FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
  61. #  define       FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
  62. #  define       FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
  63. #  define       FD_ZERO(p)      (__extension__ (void)({ \
  64.      size_t __i; \
  65.      char *__tmp = (char *)p; \
  66.      for (__i = 0; __i < sizeof (*(p)); ++__i) \
  67.        *__tmp++ = 0; \
  68. }))
  69.  
  70. #if !defined (__INSIDE_CYGWIN_NET__)
  71.  
  72. __BEGIN_DECLS
  73.  
  74. int select __P ((int __n, fd_set *__readfds, fd_set *__writefds,
  75.                  fd_set *__exceptfds, struct timeval *__timeout));
  76. int pselect __P ((int __n, fd_set *__readfds, fd_set *__writefds,
  77.                   fd_set *__exceptfds, const struct timespec *__timeout,
  78.                   const sigset_t *__set));
  79.  
  80. __END_DECLS
  81.  
  82. #endif
  83.  
  84. #endif /* !_POSIX_SOURCE, !__INSIDE_CYGWIN_NET__ */
  85.  
  86. #endif /* sys/select.h */
  87.