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 (_WINSOCK_H) || defined (_WINSOCKAPI_) || defined (__USE_W32_SOCKETS)) |
---|
23 | |
---|
24 | #include <sys/cdefs.h> |
---|
25 | #include <sys/_sigset.h> |
---|
26 | #include <sys/_timeval.h> |
---|
27 | #include <sys/timespec.h> |
---|
28 | |
---|
29 | #if !defined(_SIGSET_T_DECLARED) |
---|
30 | #define _SIGSET_T_DECLARED |
---|
31 | typedef __sigset_t sigset_t; |
---|
32 | #endif |
---|
33 | |
---|
34 | # define _SYS_TYPES_FD_SET |
---|
35 | /* |
---|
36 | * Select uses bit masks of file descriptors in longs. |
---|
37 | * These macros manipulate such bit fields (the filesystem macros use chars). |
---|
38 | * FD_SETSIZE may be defined by the user, but the default here |
---|
39 | * should be >= NOFILE (param.h). |
---|
40 | */ |
---|
41 | # ifndef FD_SETSIZE |
---|
42 | # define FD_SETSIZE 64 |
---|
43 | # endif |
---|
44 | |
---|
45 | typedef unsigned long fd_mask; |
---|
46 | # define NFDBITS (sizeof (fd_mask) * 8) /* bits per mask */ |
---|
47 | # ifndef _howmany |
---|
48 | # define _howmany(x,y) (((x)+((y)-1))/(y)) |
---|
49 | # endif |
---|
50 | |
---|
51 | /* We use a macro for fd_set so that including Sockets.h afterwards |
---|
52 | can work. */ |
---|
53 | typedef struct _types_fd_set { |
---|
54 | fd_mask fds_bits[_howmany(FD_SETSIZE, NFDBITS)]; |
---|
55 | } _types_fd_set; |
---|
56 | |
---|
57 | #define fd_set _types_fd_set |
---|
58 | |
---|
59 | # define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) |
---|
60 | # define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) |
---|
61 | # define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) |
---|
62 | # define FD_ZERO(p) (__extension__ (void)({ \ |
---|
63 | size_t __i; \ |
---|
64 | char *__tmp = (char *)p; \ |
---|
65 | for (__i = 0; __i < sizeof (*(p)); ++__i) \ |
---|
66 | *__tmp++ = 0; \ |
---|
67 | })) |
---|
68 | |
---|
69 | #if !defined (__INSIDE_CYGWIN_NET__) |
---|
70 | |
---|
71 | __BEGIN_DECLS |
---|
72 | |
---|
73 | int select __P ((int __n, fd_set *__readfds, fd_set *__writefds, |
---|
74 | fd_set *__exceptfds, struct timeval *__timeout)); |
---|
75 | #if __POSIX_VISIBLE >= 200112 |
---|
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 | #endif |
---|
80 | |
---|
81 | __END_DECLS |
---|
82 | |
---|
83 | #endif /* !__INSIDE_CYGWIN_NET__ */ |
---|
84 | |
---|
85 | #endif /* !(_WINSOCK_H || _WINSOCKAPI_ || __USE_W32_SOCKETS) */ |
---|
86 | |
---|
87 | #endif /* sys/select.h */ |
---|