xref: /haiku/headers/posix/sys/select.h (revision 2600324b57fa31cdea1627d584d314f2a579c4a8)
1 /*
2  * Copyright 2002-2006, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _SYS_SELECT_H
6 #define _SYS_SELECT_H
7 
8 
9 #include <sys/time.h>
10 #include <signal.h>
11 
12 
13 /* If FD_SET is already defined, only the select() prototype is
14  * exported in this header.
15  */
16 #ifndef FD_SET
17 
18 /* You can define your own FDSETSIZE if you need more bits - but
19  * it should be enough for most uses.
20  */
21 #ifndef FD_SETSIZE
22 #	define FD_SETSIZE 1024
23 #endif
24 
25 typedef unsigned long fd_mask;
26 
27 #ifndef _howmany
28 #	define _howmany(x, y) (((x) + ((y) - 1)) / (y))
29 #endif
30 
31 #ifndef howmany
32 #	define howmany(x, y) (((x) + ((y) - 1)) / (y))
33 #endif
34 
35 #define NFDBITS (sizeof(fd_mask) * 8)	/* bits per mask */
36 
37 typedef struct fd_set {
38 	fd_mask bits[_howmany(FD_SETSIZE, NFDBITS)];
39 } fd_set;
40 
41 #define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
42 #define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
43 
44 #define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
45 #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
46 #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
47 #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
48 #define FD_COPY(source, target) (*(target) = *(source))
49 
50 #endif	/* FD_SET */
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 extern int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
57 			struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask);
58 extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
59 			struct fd_set *errorBits, struct timeval *timeout);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif	/* _SYS_SELECT_H */
66