Source to include/select.h
0001 /*
0002 * select.h
0003 * Definitions for select() operations
0004 */
0005 #ifndef _SELECT_H
0006 #define _SELECT_H
0007 #include <sys/types.h>
0008 #include <sys/param.h>
0009 #include <time.h>
0010
0011 /*
0012 * By default, size of a file descriptor set. May be overriden.
0013 * Must be a power of two, and a multiple of FDBITS.
0014 */
0015 #ifndef FD_SETSIZE
0016 #define FD_SETSIZE (64)
0017 #endif
0018
0019 /*
0020 * Bits per slot (uint) in an fd_set
0021 */
0022 #define FDBITS (sizeof(uint) * NBBY)
0023
0024 typedef struct fd_set {
0025 uint _fds[FD_SETSIZE / FDBITS];
0026 } fd_set;
0027
0028 extern int select(uint, fd_set *, fd_set *, fd_set *, struct timeval *);
0029
0030 #define FD_ISSET(idx, p) \
0031 ((p)->_fds[(idx) / FDBITS] & \
0032 (1 << ((idx) & (FDBITS - 1))))
0033
0034 #define FD_SET(idx, p) \
0035 ((p)->_fds[(idx) / FDBITS] |= \
0036 (1 << ((idx) & (FDBITS - 1))))
0037
0038 #define FD_CLR(idx, p) \
0039 ((p)->_fds[(idx) / FDBITS] &= \
0040 ~(1 << ((idx) & (FDBITS - 1))))
0041
0042 #define FD_ZERO(p) bzero((p), sizeof(fd_set))
0043
0044
0045 /*
0046 * Aliases for some access bits we use for our own purposes
0047 */
0048 #define ACC_EXCEP ACC_EXEC
0049 #define ACC_UNSUPP ACC_SYM /* Internal */
0050
0051 #ifdef _SELFS_INTERNAL
0052
0053 /*
0054 * Format of messages used to control selfs
0055 */
0056
0057 /*
0058 * This is the format of data returned from an FS_READ to a client. It
0059 * indicates which sources satisfied the select request. Zero (for timeout)
0060 * or more of these will be returned as the FS_READ data.
0061 */
0062 struct select_complete {
0063 uint sc_index; /* Index of client connection */
0064 uint sc_mask; /* Mask of satisfied events */
0065 ulong sc_iocount; /* # message exchanges seen */
0066 };
0067
0068 /*
0069 * A server will write one or more of these to selfs to indicate
0070 * events which should awake a client.
0071 */
0072 struct select_event {
0073 long se_clid; /* Client's connection ID */
0074 ulong se_key; /* Magic # to inhibit bogus clid's */
0075 uint se_index; /* Index of client's server connection */
0076 uint se_mask; /* Mask of events which have occurred */
0077 ulong se_iocount; /* Indicated sc_iocount for this event */
0078 };
0079
0080 /*
0081 * While not a struct, the format of the data which a client writes to a
0082 * server in an FS_WSTAT message is:
0083 * select=<mask>,<host>,<se_clid>,<se_index>,<key>
0084 * or:
0085 * unselect=<mask>,<host>,<se_clid>,<se_index>,<key>
0086 * The server's iocount is expected to count up from 0 starting from this
0087 * point.
0088 */
0089
0090 #endif /* _SELFS_INTERNAL */
0091
0092 #endif /* _SELECT_H */