1 /* 2 * Copyright 2002-2012 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 14 15 /* If FD_SET is already defined, only the select() prototype is 16 * exported in this header. 17 */ 18 #ifndef FD_SET 19 20 /* You can define your own FDSETSIZE if you need more bits - but 21 * it should be enough for most uses. 22 */ 23 #ifndef FD_SETSIZE 24 # define FD_SETSIZE 1024 25 #endif 26 27 typedef __haiku_uint32 fd_mask; 28 29 #define NFDBITS (sizeof(fd_mask) * 8) /* bits per mask */ 30 31 typedef struct fd_set { 32 fd_mask bits[((FD_SETSIZE) + ((NFDBITS) - 1)) / (NFDBITS)]; 33 } fd_set; 34 35 #define _FD_BITSINDEX(fd) ((fd) / NFDBITS) 36 #define _FD_BIT(fd) (1L << ((fd) % NFDBITS)) 37 38 /* FD_ZERO uses memset */ 39 #include <string.h> 40 41 #define FD_ZERO(set) memset((set), 0, sizeof(fd_set)) 42 #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd)) 43 #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd)) 44 #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd)) 45 #define FD_COPY(source, target) (*(target) = *(source)) 46 47 #endif /* FD_SET */ 48 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 extern int pselect(int numBits, struct fd_set *readBits, struct fd_set *writeBits, 55 struct fd_set *errorBits, const struct timespec *timeout, const sigset_t *sigMask); 56 extern int select(int numBits, struct fd_set *readBits, struct fd_set *writeBits, 57 struct fd_set *errorBits, struct timeval *timeout); 58 59 #ifdef __cplusplus 60 } 61 #endif 62 63 #endif /* _SYS_SELECT_H */ 64