Changed FD_* select() fd set manipulation functions to macros. Also
made FD_SETSIZE pre-#include-definable, with OPEN_MAX as default if unset.
This commit is contained in:
parent
f0817fbd4c
commit
1adcfcdf1c
@ -5,6 +5,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* Use this datatype as basic storage unit in fd_set */
|
/* Use this datatype as basic storage unit in fd_set */
|
||||||
typedef u32_t _fdsetword;
|
typedef u32_t _fdsetword;
|
||||||
@ -12,11 +13,17 @@ typedef u32_t _fdsetword;
|
|||||||
/* This many bits fit in an fd_set word. */
|
/* This many bits fit in an fd_set word. */
|
||||||
#define _FDSETBITSPERWORD (sizeof(_fdsetword)*8)
|
#define _FDSETBITSPERWORD (sizeof(_fdsetword)*8)
|
||||||
|
|
||||||
/* We want to store OPEN_MAX fd bits. */
|
/* Bit manipulation macros */
|
||||||
#define _FDSETWORDS ((OPEN_MAX+_FDSETBITSPERWORD-1)/_FDSETBITSPERWORD)
|
#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
|
#define FD_SETSIZE OPEN_MAX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* We want to store FD_SETSIZE bits. */
|
||||||
|
#define _FDSETWORDS ((FD_SETSIZE+_FDSETBITSPERWORD-1)/_FDSETBITSPERWORD)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
_fdsetword _fdsetval[_FDSETWORDS];
|
_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( 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));
|
#define FD_ZERO(s) do { memset((s), sizeof(s), 0); } while(0)
|
||||||
_PROTOTYPE( int FD_ISSET, (int fd, fd_set *fdset));
|
#define FD_SET(f, s) do { (s)->_fdsetval[_FD_BITWORD(f)] |= _FD_BITMASK(f); } while(0)
|
||||||
_PROTOTYPE( void FD_SET, (int fd, fd_set *fdset));
|
#define FD_CLR(f, s) do { (s)->_fdsetval[_FD_BITWORD(f)] &= ~(_FD_BITMASK(f)); } while(0)
|
||||||
_PROTOTYPE( void FD_ZERO, (fd_set *fdset));
|
#define FD_ISSET(f, s) ((s)->_fdsetval[_FD_BITWORD(f)] & _FD_BITMASK(f))
|
||||||
|
|
||||||
/* possible select() operation types; read, write, errors */
|
/* possible select() operation types; read, write, errors */
|
||||||
/* (FS/driver internal use only) */
|
/* (FS/driver internal use only) */
|
||||||
|
@ -18,38 +18,3 @@ PUBLIC int select(int nfds,
|
|||||||
return (_syscall(FS, SELECT, &m));
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user