2005-06-06 13:40:32 +02:00
|
|
|
#ifndef _SYS_SELECT_H
|
|
|
|
#define _SYS_SELECT_H 1
|
|
|
|
|
2005-09-30 14:41:25 +02:00
|
|
|
#ifndef _POSIX_SOURCE
|
|
|
|
#define _POSIX_SOURCE 1
|
|
|
|
#endif
|
|
|
|
|
2005-06-28 17:01:55 +02:00
|
|
|
#include <sys/time.h>
|
2005-06-06 13:40:32 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <limits.h>
|
2005-07-06 09:22:21 +02:00
|
|
|
#include <string.h>
|
2005-06-06 13:40:32 +02:00
|
|
|
|
|
|
|
/* Use this datatype as basic storage unit in fd_set */
|
2005-07-11 15:00:43 +02:00
|
|
|
typedef u32_t fd_mask;
|
2005-06-06 13:40:32 +02:00
|
|
|
|
|
|
|
/* This many bits fit in an fd_set word. */
|
2005-07-11 15:00:43 +02:00
|
|
|
#define _FDSETBITSPERWORD (sizeof(fd_mask)*8)
|
2005-06-06 13:40:32 +02:00
|
|
|
|
2005-07-06 09:22:21 +02:00
|
|
|
/* Bit manipulation macros */
|
|
|
|
#define _FD_BITMASK(b) (1L << ((b) % _FDSETBITSPERWORD))
|
|
|
|
#define _FD_BITWORD(b) ((b)/_FDSETBITSPERWORD)
|
2005-06-06 13:40:32 +02:00
|
|
|
|
2005-07-06 09:22:21 +02:00
|
|
|
/* Default FD_SETSIZE is OPEN_MAX. */
|
|
|
|
#ifndef FD_SETSIZE
|
2005-06-06 13:40:32 +02:00
|
|
|
#define FD_SETSIZE OPEN_MAX
|
2005-07-06 09:22:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* We want to store FD_SETSIZE bits. */
|
2006-10-06 17:45:13 +02:00
|
|
|
#define _FDSETWORDS(b) (((b)+_FDSETBITSPERWORD-1)/_FDSETBITSPERWORD)
|
2005-06-06 13:40:32 +02:00
|
|
|
|
|
|
|
typedef struct {
|
2006-10-06 17:45:13 +02:00
|
|
|
fd_mask fds_bits[_FDSETWORDS(FD_SETSIZE)];
|
2005-06-06 13:40:32 +02:00
|
|
|
} fd_set;
|
|
|
|
|
|
|
|
_PROTOTYPE( int select, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout) );
|
|
|
|
|
2006-10-06 17:45:13 +02:00
|
|
|
#define FD_ZERO(s) do { int _i; for(_i = 0; _i < _FDSETWORDS(FD_SETSIZE); _i++) { (s)->fds_bits[_i] = 0; } } while(0)
|
2005-07-12 15:10:06 +02:00
|
|
|
#define FD_SET(f, s) do { (s)->fds_bits[_FD_BITWORD(f)] |= _FD_BITMASK(f); } while(0)
|
|
|
|
#define FD_CLR(f, s) do { (s)->fds_bits[_FD_BITWORD(f)] &= ~(_FD_BITMASK(f)); } while(0)
|
|
|
|
#define FD_ISSET(f, s) ((s)->fds_bits[_FD_BITWORD(f)] & _FD_BITMASK(f))
|
2005-06-06 13:40:32 +02:00
|
|
|
|
2005-06-17 15:34:47 +02:00
|
|
|
/* possible select() operation types; read, write, errors */
|
|
|
|
/* (FS/driver internal use only) */
|
|
|
|
#define SEL_RD (1 << 0)
|
|
|
|
#define SEL_WR (1 << 1)
|
|
|
|
#define SEL_ERR (1 << 2)
|
|
|
|
#define SEL_NOTIFY (1 << 3) /* not a real select operation */
|
|
|
|
|
2005-06-06 13:40:32 +02:00
|
|
|
#endif /* _SYS_SELECT_H */
|
|
|
|
|