From: Ben Gras Date: Wed, 6 Jul 2005 07:22:21 +0000 (+0000) Subject: Changed FD_* select() fd set manipulation functions to macros. Also X-Git-Tag: v3.1.0~644 X-Git-Url: http://zhaoyanbai.com/repos/%22../static/howto.html?a=commitdiff_plain;h=1adcfcdf1c955d268f5e931b83af8ce4428a3b67;p=minix.git Changed FD_* select() fd set manipulation functions to macros. Also made FD_SETSIZE pre-#include-definable, with OPEN_MAX as default if unset. --- diff --git a/include/sys/select.h b/include/sys/select.h index 8517124b6..96f7cc015 100755 --- a/include/sys/select.h +++ b/include/sys/select.h @@ -5,6 +5,7 @@ #include #include #include +#include /* Use this datatype as basic storage unit in fd_set */ typedef u32_t _fdsetword; @@ -12,11 +13,17 @@ typedef u32_t _fdsetword; /* This many bits fit in an fd_set word. */ #define _FDSETBITSPERWORD (sizeof(_fdsetword)*8) -/* We want to store OPEN_MAX fd bits. */ -#define _FDSETWORDS ((OPEN_MAX+_FDSETBITSPERWORD-1)/_FDSETBITSPERWORD) +/* Bit manipulation macros */ +#define _FD_BITMASK(b) (1L << ((b) % _FDSETBITSPERWORD)) +#define _FD_BITWORD(b) ((b)/_FDSETBITSPERWORD) -/* This means we can store all of OPEN_MAX. */ +/* Default FD_SETSIZE is OPEN_MAX. */ +#ifndef FD_SETSIZE #define FD_SETSIZE OPEN_MAX +#endif + +/* We want to store FD_SETSIZE bits. */ +#define _FDSETWORDS ((FD_SETSIZE+_FDSETBITSPERWORD-1)/_FDSETBITSPERWORD) typedef struct { _fdsetword _fdsetval[_FDSETWORDS]; @@ -24,10 +31,10 @@ typedef struct { _PROTOTYPE( int select, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout) ); -_PROTOTYPE( void FD_CLR, (int fd, fd_set *fdset)); -_PROTOTYPE( int FD_ISSET, (int fd, fd_set *fdset)); -_PROTOTYPE( void FD_SET, (int fd, fd_set *fdset)); -_PROTOTYPE( void FD_ZERO, (fd_set *fdset)); +#define FD_ZERO(s) do { memset((s), sizeof(s), 0); } while(0) +#define FD_SET(f, s) do { (s)->_fdsetval[_FD_BITWORD(f)] |= _FD_BITMASK(f); } while(0) +#define FD_CLR(f, s) do { (s)->_fdsetval[_FD_BITWORD(f)] &= ~(_FD_BITMASK(f)); } while(0) +#define FD_ISSET(f, s) ((s)->_fdsetval[_FD_BITWORD(f)] & _FD_BITMASK(f)) /* possible select() operation types; read, write, errors */ /* (FS/driver internal use only) */ diff --git a/lib/posix/_select.c b/lib/posix/_select.c index 4b86d1c97..7d46e6de7 100755 --- a/lib/posix/_select.c +++ b/lib/posix/_select.c @@ -18,38 +18,3 @@ PUBLIC int select(int nfds, return (_syscall(FS, SELECT, &m)); } -#define FD_BITMASK(b) (1L << ((b) % _FDSETBITSPERWORD)) -#define FD_BITWORD(b) ((b)/_FDSETBITSPERWORD) - -PUBLIC void FD_CLR(int fd, fd_set *fdset) -{ - if(fd < 0 || fd >= FD_SETSIZE) return; - fdset->_fdsetval[FD_BITWORD(fd)] &= ~(FD_BITMASK(fd)); - return; -} - -PUBLIC int FD_ISSET(int fd, fd_set *fdset) -{ - if(fd < 0 || fd >= FD_SETSIZE) - return 0; - if(fdset->_fdsetval[FD_BITWORD(fd)] & FD_BITMASK(fd)) - return 1; - return 0; -} - -PUBLIC void FD_SET(int fd, fd_set *fdset) -{ - if(fd < 0 || fd >= FD_SETSIZE) - return; - fdset->_fdsetval[FD_BITWORD(fd)] |= FD_BITMASK(fd); - return; -} - -PUBLIC void FD_ZERO(fd_set *fdset) -{ - int i; - for(i = 0; i < _FDSETWORDS; i++) - fdset->_fdsetval[i] = 0; - return; -} -