1 | #ifndef _SYS_SELECT_H
|
---|
2 | #define _SYS_SELECT_H 1
|
---|
3 |
|
---|
4 | #ifndef _POSIX_SOURCE
|
---|
5 | #define _POSIX_SOURCE 1
|
---|
6 | #endif
|
---|
7 |
|
---|
8 | #include <sys/time.h>
|
---|
9 | #include <sys/types.h>
|
---|
10 | #include <limits.h>
|
---|
11 | #include <string.h>
|
---|
12 |
|
---|
13 | /* Use this datatype as basic storage unit in fd_set */
|
---|
14 | typedef u32_t fd_mask;
|
---|
15 |
|
---|
16 | /* This many bits fit in an fd_set word. */
|
---|
17 | #define _FDSETBITSPERWORD (sizeof(fd_mask)*8)
|
---|
18 |
|
---|
19 | /* Bit manipulation macros */
|
---|
20 | #define _FD_BITMASK(b) (1L << ((b) % _FDSETBITSPERWORD))
|
---|
21 | #define _FD_BITWORD(b) ((b)/_FDSETBITSPERWORD)
|
---|
22 |
|
---|
23 | /* Default FD_SETSIZE is OPEN_MAX. */
|
---|
24 | #ifndef FD_SETSIZE
|
---|
25 | #define FD_SETSIZE OPEN_MAX
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /* We want to store FD_SETSIZE bits. */
|
---|
29 | #define _FDSETWORDS ((FD_SETSIZE+_FDSETBITSPERWORD-1)/_FDSETBITSPERWORD)
|
---|
30 |
|
---|
31 | typedef struct {
|
---|
32 | fd_mask fds_bits[_FDSETWORDS];
|
---|
33 | } fd_set;
|
---|
34 |
|
---|
35 | _PROTOTYPE( int select, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout) );
|
---|
36 |
|
---|
37 | #define FD_ZERO(s) do { int _i; for(_i = 0; _i < _FDSETWORDS; _i++) { (s)->fds_bits[_i] = 0; } } while(0)
|
---|
38 | #define FD_SET(f, s) do { (s)->fds_bits[_FD_BITWORD(f)] |= _FD_BITMASK(f); } while(0)
|
---|
39 | #define FD_CLR(f, s) do { (s)->fds_bits[_FD_BITWORD(f)] &= ~(_FD_BITMASK(f)); } while(0)
|
---|
40 | #define FD_ISSET(f, s) ((s)->fds_bits[_FD_BITWORD(f)] & _FD_BITMASK(f))
|
---|
41 |
|
---|
42 | /* possible select() operation types; read, write, errors */
|
---|
43 | /* (FS/driver internal use only) */
|
---|
44 | #define SEL_RD (1 << 0)
|
---|
45 | #define SEL_WR (1 << 1)
|
---|
46 | #define SEL_ERR (1 << 2)
|
---|
47 | #define SEL_NOTIFY (1 << 3) /* not a real select operation */
|
---|
48 |
|
---|
49 | #endif /* _SYS_SELECT_H */
|
---|
50 |
|
---|