1d3dadb6bSPhilippe Houdoin #ifndef _SYS_SELECT_H 2d3dadb6bSPhilippe Houdoin #define _SYS_SELECT_H 3d3dadb6bSPhilippe Houdoin /* 4*493130b3SAxel Dörfler ** Distributed under the terms of the OpenBeOS License. 5d3dadb6bSPhilippe Houdoin */ 6d3dadb6bSPhilippe Houdoin 7*493130b3SAxel Dörfler #include <sys/time.h> 8*493130b3SAxel Dörfler 9*493130b3SAxel Dörfler 10*493130b3SAxel Dörfler /* If FD_SET is already defined, only the select() prototype is 11*493130b3SAxel Dörfler * exported in this header. 12*493130b3SAxel Dörfler */ 13*493130b3SAxel Dörfler #ifndef FD_SET 14*493130b3SAxel Dörfler 15*493130b3SAxel Dörfler /* You can define your own FDSETSIZE if you need more bits - but 16*493130b3SAxel Dörfler * it should be enough for most uses. 17*493130b3SAxel Dörfler */ 18d3dadb6bSPhilippe Houdoin #ifndef FD_SETSIZE 19d3dadb6bSPhilippe Houdoin # define FD_SETSIZE 1024 20*493130b3SAxel Dörfler #endif 21d3dadb6bSPhilippe Houdoin 22*493130b3SAxel Dörfler /* Compatibily only: use FD_SETSIZE instead */ 23*493130b3SAxel Dörfler #ifndef FDSETSIZE 24*493130b3SAxel Dörfler # define FDSETSIZE FD_SETSIZE 25*493130b3SAxel Dörfler #endif 26*493130b3SAxel Dörfler 27*493130b3SAxel Dörfler /* compatibility with BSD */ 28d3dadb6bSPhilippe Houdoin #define NBBY 8 /* number of bits in a byte */ 29d3dadb6bSPhilippe Houdoin 30d3dadb6bSPhilippe Houdoin typedef unsigned long fd_mask; 31d3dadb6bSPhilippe Houdoin 32d3dadb6bSPhilippe Houdoin #ifndef howmany 33d3dadb6bSPhilippe Houdoin # define howmany(x, y) (((x) + ((y) - 1)) / (y)) 34d3dadb6bSPhilippe Houdoin #endif 35d3dadb6bSPhilippe Houdoin 36*493130b3SAxel Dörfler #define NFDBITS (sizeof(fd_mask) * NBBY) 37d3dadb6bSPhilippe Houdoin 38d3dadb6bSPhilippe Houdoin typedef struct fd_set { 39*493130b3SAxel Dörfler fd_mask bits[howmany(FD_SETSIZE, NFDBITS)]; 40d3dadb6bSPhilippe Houdoin } fd_set; 41d3dadb6bSPhilippe Houdoin 42*493130b3SAxel Dörfler #define _FD_BITSINDEX(fd) ((fd) / NFDBITS) 43*493130b3SAxel Dörfler #define _FD_BIT(fd) (1L << ((fd) % NFDBITS)) 44d3dadb6bSPhilippe Houdoin 45*493130b3SAxel Dörfler #define FD_ZERO(set) memset((set), 0, sizeof(fd_set)) 46*493130b3SAxel Dörfler #define FD_SET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] |= _FD_BIT(fd)) 47*493130b3SAxel Dörfler #define FD_CLR(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] &= ~_FD_BIT(fd)) 48*493130b3SAxel Dörfler #define FD_ISSET(fd, set) ((set)->bits[_FD_BITSINDEX(fd)] & _FD_BIT(fd)) 49d3dadb6bSPhilippe Houdoin 50*493130b3SAxel Dörfler #endif /* FD_SET */ 51*493130b3SAxel Dörfler 52*493130b3SAxel Dörfler extern 53*493130b3SAxel Dörfler #ifdef __cplusplus 54*493130b3SAxel Dörfler "C" 55*493130b3SAxel Dörfler #endif 56*493130b3SAxel Dörfler int select(int nbits, struct fd_set *rbits, struct fd_set *wbits, 57*493130b3SAxel Dörfler struct fd_set *ebits, struct timeval *timeout); 58d3dadb6bSPhilippe Houdoin 59d3dadb6bSPhilippe Houdoin #endif /* _SYS_SELECT_H */ 60