1 /* select.h */ 2 3 #ifndef _SYS_SELECT_H 4 #define _SYS_SELECT_H 5 6 #include <sys/time.h> /* for struct timeval */ 7 /* 8 * You can define your own FDSETSIZE if you want more bits 9 */ 10 11 #ifndef FD_SETSIZE 12 #define FD_SETSIZE 1024 13 #endif /* FD_SETSIZE */ 14 15 /* compatability with BSD */ 16 #define NBBY 8 /* number of bits in a byte */ 17 18 typedef unsigned long fd_mask; 19 20 #ifndef howmany 21 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 22 #endif 23 24 /* 25 * Compatibily only: use FD_SETSIZE instead 26 */ 27 #ifndef FDSETSIZE 28 #define FDSETSIZE FD_SETSIZE 29 #endif /* FDSETSIZE */ 30 31 #define NFDBITS 32 32 33 typedef struct fd_set { 34 unsigned mask[FDSETSIZE / NFDBITS]; 35 } fd_set; 36 37 #define _FDMSKNO(fd) ((fd) / NFDBITS) 38 #define _FDBITNO(fd) ((fd) % NFDBITS) 39 40 #define FD_ZERO(setp) memset((setp)->mask, 0, sizeof((setp)->mask)) 41 #define FD_SET(fd, setp) ((setp)->mask[_FDMSKNO(fd)] |= (1 << (_FDBITNO(fd)))) 42 #define FD_CLR(fd, setp) ((setp)->mask[_FDMSKNO(fd)] &= ~(1 << (_FDBITNO(fd)))) 43 #define FD_ISSET(fd, setp) ((setp)->mask[_FDMSKNO(fd)] & (1 << (_FDBITNO(fd)))) 44 45 int select(int nbits, struct fd_set *rbits, 46 struct fd_set *wbits, 47 struct fd_set *ebits, 48 struct timeval *timeout); 49 50 #endif /* _SYS_SELECT_H */ 51