select.h


    1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
    2 /*	Copyright (c) 1998 by Sun Microsystems, Inc.	*/
    3 /*	  All Rights Reserved  	*/
    4 
    5 /*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
    6 /*	The copyright notice above does not evidence any   	*/
    7 /*	actual or intended publication of such source code.	*/
    8 
    9 #ifndef _SYS_SELECT_H
    10 #define	_SYS_SELECT_H
    11 
    12 #pragma ident	"@(#)select.h	1.16	98/04/27 SMI"	/* SVr4.0 1.2 */
    13 
    14 #include 
    15 
    16 #ifndef _KERNEL
    17 #include 
    18 #endif
    19 
    20 #ifdef	__cplusplus
    21 extern "C" {
    22 #endif
    23 
    24 /*
    25  * Select uses bit masks of file descriptors in longs.
    26  * These macros manipulate such bit fields.
    27  * FD_SETSIZE may be defined by the user, but the default here
    28  * should be >= NOFILE (param.h).
    29  */
    30 #ifndef	FD_SETSIZE
    31 #ifdef _LP64
    32 #define	FD_SETSIZE	65536
    33 #else
    34 #define	FD_SETSIZE	1024
    35 #endif	/* _LP64 */
    36 #elif FD_SETSIZE > 1024 && !defined(_LP64)
    37 #ifdef __PRAGMA_REDEFINE_EXTNAME
    38 #pragma	redefine_extname	select	select_large_fdset
    39 #else	/* __PRAGMA_REDEFINE_EXTNAME */
    40 #define	select	select_large_fdset
    41 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
    42 #endif	/* FD_SETSIZE */
    43 
    44 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
    45 typedef	long	fd_mask;  <typedef:fd_mask>
    46 #endif
    47 typedef	long	fds_mask;  <typedef:fds_mask>
    48 
    49 /*
    50  *  The value of _NBBY needs to be consistant with the value
    51  *  of NBBY in .
    52  */
    53 #define	_NBBY 8
    54 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
    55 #ifndef NBBY		/* number of bits per byte */
    56 #define	NBBY _NBBY
    57 #endif
    58 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
    59 
    60 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
    61 #define	NFDBITS		(sizeof (fd_mask) * NBBY)	/* bits per mask */
    62 #endif
    63 #define	FD_NFDBITS	(sizeof (fds_mask) * _NBBY)	/* bits per mask */
    64 
    65 #define	__howmany(__x, __y)	(((__x)+((__y)-1))/(__y))
    66 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
    67 #ifndef	howmany
    68 #define	howmany(x, y)	(((x)+((y)-1))/(y))
    69 #endif
    70 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
    71 
    72 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
    73 typedef	struct fd_set {  <fd_set>
    74 #else
    75 typedef	struct __fd_set {
    76 #endif
    77 	long	fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
    78 } fd_set;  <typedef:fd_set>
    79 
    80 #define	FD_SET(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
    81 				    (1ul << ((__n) % FD_NFDBITS)))
    82 
    83 #define	FD_CLR(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
    84 				    ~(1ul << ((__n) % FD_NFDBITS)))
    85 
    86 #define	FD_ISSET(__n, __p)	(((__p)->fds_bits[(__n)/FD_NFDBITS] & \
    87 				    (1ul << ((__n) % FD_NFDBITS))) != 0l)
    88 
    89 #ifdef _KERNEL
    90 #define	FD_ZERO(p)	bzero((p), sizeof (*(p)))
    91 #else
    92 #define	FD_ZERO(__p)	memset((void *)(__p), 0, sizeof (*(__p)))
    93 #endif /* _KERNEL */
    94 
    95 #ifndef	_KERNEL
    96 #ifdef	__STDC__
    97 extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    98 #else
    99 extern int select();
    100 #endif	/* __STDC__ */
    101 #endif	/* _KERNEL */
    102 
    103 #ifdef	__cplusplus
    104 }
    105 #endif
    106 
    107 #endif	/* _SYS_SELECT_H */