xref: /haiku/headers/posix/sys/select.h (revision 8b5cc9cf52bc7de09b9fa2db0f16fced0f4ae2e9)
1 /*
2  * Copyright 2002-2024, 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 <config/types.h>
10 
11 #include <sys/time.h>
12 #include <signal.h>
13 #include <string.h>
14 
15 
16 /* Custom FD_SETSIZEs can be defined if more bits are needed, but the default
17  * should suffice for most uses. */
18 #ifndef FD_SETSIZE
19 #	define FD_SETSIZE	1024
20 #endif
21 
22 typedef __haiku_uint32 fd_mask;
23 
24 #define NFDBITS		(sizeof(fd_mask) * 8)	/* bits per mask */
25 
26 typedef struct fd_set {
27 	fd_mask bits[((FD_SETSIZE) + ((NFDBITS) - 1)) / (NFDBITS)];
28 } fd_set;
29 
30 #define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
31 #define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
32 
33 #define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
34 #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
35 #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
36 #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
37 #define FD_COPY(source, target) (*(target) = *(source))
38 
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 extern int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
45 			struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask);
46 extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits,
47 			struct fd_set *errorBits, struct timeval *timeout);
48 
49 #ifdef __cplusplus
50 }
51 #endif
52 
53 
54 #endif	/* _SYS_SELECT_H */
55