xref: /haiku/headers/posix/sys/select.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
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 #define NFDBITS (sizeof(fd_mask) * 8)	/* bits per mask */
32 
33 typedef struct fd_set {
34 	fd_mask bits[_howmany(FD_SETSIZE, NFDBITS)];
35 } fd_set;
36 
37 #define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
38 #define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
39 
40 #define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
41 #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
42 #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
43 #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
44 
45 #endif	/* FD_SET */
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 extern int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
52 			struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask);
53 extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
54 			struct fd_set *errorBits, struct timeval *timeout);
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #endif	/* _SYS_SELECT_H */
61