2 * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
9 #include <config/types.h>
15 /* If FD_SET is already defined, only the select() prototype is
16 * exported in this header.
20 /* You can define your own FDSETSIZE if you need more bits - but
21 * it should be enough for most uses.
24 # define FD_SETSIZE 1024
27 typedef __haiku_uint32 fd_mask
;
30 # define _howmany(x, y) (((x) + ((y) - 1)) / (y))
34 # define howmany(x, y) (((x) + ((y) - 1)) / (y))
37 #define NFDBITS (sizeof(fd_mask) * 8) /* bits per mask */
39 typedef struct fd_set
{
40 fd_mask bits
[_howmany(FD_SETSIZE
, NFDBITS
)];
43 #define _FD_BITSINDEX(fd) ((fd) / NFDBITS)
44 #define _FD_BIT(fd) (1L << ((fd) % NFDBITS))
46 /* FD_ZERO uses memset */
49 #define FD_ZERO(set) memset((set), 0, sizeof(fd_set))
50 #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd))
51 #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd))
52 #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd))
53 #define FD_COPY(source, target) (*(target) = *(source))
61 extern int pselect(int numBits
, struct fd_set
*readBits
, struct fd_set
*writeBits
,
62 struct fd_set
*errorBits
, const struct timespec
*timeout
, const sigset_t
*sigMask
);
63 extern int select(int numBits
, struct fd_set
*readBits
, struct fd_set
*writeBits
,
64 struct fd_set
*errorBits
, struct timeval
*timeout
);
70 #endif /* _SYS_SELECT_H */