xref: /onnv-gate/usr/src/uts/common/sys/select.h (revision 11913:283e725df792)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11913SRoger.Faulkner@Sun.COM  * Common Development and Distribution License (the "License").
6*11913SRoger.Faulkner@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*11913SRoger.Faulkner@Sun.COM 
220Sstevel@tonic-gate /*
23*11913SRoger.Faulkner@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate  * The Regents of the University of California
330Sstevel@tonic-gate  * All Rights Reserved
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate  * contributors.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifndef _SYS_SELECT_H
410Sstevel@tonic-gate #define	_SYS_SELECT_H
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include <sys/feature_tests.h>
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifndef _KERNEL
460Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
470Sstevel@tonic-gate #include <sys/time_impl.h>
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate #include <sys/time.h>
500Sstevel@tonic-gate #endif /* _KERNEL */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #ifdef	__cplusplus
530Sstevel@tonic-gate extern "C" {
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * The sigset_t type is defined in <sys/signal.h> and duplicated
600Sstevel@tonic-gate  * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
610Sstevel@tonic-gate  * now allows the visibility of signal.h in this header, however
620Sstevel@tonic-gate  * an order of inclusion problem occurs as a result of inclusion
630Sstevel@tonic-gate  * of <sys/select.h> in <signal.h> under certain conditions.
640Sstevel@tonic-gate  * Rather than include <sys/signal.h> here, we've duplicated
650Sstevel@tonic-gate  * the sigset_t type instead. This type is required for the XPG6
660Sstevel@tonic-gate  * introduced pselect() function also declared in this header.
670Sstevel@tonic-gate  */
680Sstevel@tonic-gate #ifndef	_SIGSET_T
690Sstevel@tonic-gate #define	_SIGSET_T
700Sstevel@tonic-gate typedef struct {		/* signal set type */
710Sstevel@tonic-gate 	unsigned int	__sigbits[4];
720Sstevel@tonic-gate } sigset_t;
730Sstevel@tonic-gate #endif  /* _SIGSET_T */
740Sstevel@tonic-gate 
750Sstevel@tonic-gate #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * Select uses bit masks of file descriptors in longs.
790Sstevel@tonic-gate  * These macros manipulate such bit fields.
800Sstevel@tonic-gate  * FD_SETSIZE may be defined by the user, but the default here
810Sstevel@tonic-gate  * should be >= NOFILE (param.h).
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate #ifndef	FD_SETSIZE
840Sstevel@tonic-gate #ifdef _LP64
850Sstevel@tonic-gate #define	FD_SETSIZE	65536
860Sstevel@tonic-gate #else
870Sstevel@tonic-gate #define	FD_SETSIZE	1024
880Sstevel@tonic-gate #endif	/* _LP64 */
890Sstevel@tonic-gate #elif FD_SETSIZE > 1024 && !defined(_LP64)
900Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
910Sstevel@tonic-gate #pragma	redefine_extname	select	select_large_fdset
920Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
930Sstevel@tonic-gate #pragma	redefine_extname	pselect	pselect_large_fdset
940Sstevel@tonic-gate #endif
950Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
960Sstevel@tonic-gate #define	select	select_large_fdset
970Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
980Sstevel@tonic-gate #define	pselect	pselect_large_fdset
990Sstevel@tonic-gate #endif
1000Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
1010Sstevel@tonic-gate #endif	/* FD_SETSIZE */
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1040Sstevel@tonic-gate typedef	long	fd_mask;
1050Sstevel@tonic-gate #endif
1060Sstevel@tonic-gate typedef	long	fds_mask;
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  *  The value of _NBBY needs to be consistant with the value
1100Sstevel@tonic-gate  *  of NBBY in <sys/param.h>.
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate #define	_NBBY 8
1130Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1140Sstevel@tonic-gate #ifndef NBBY		/* number of bits per byte */
1150Sstevel@tonic-gate #define	NBBY _NBBY
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1200Sstevel@tonic-gate #define	NFDBITS		(sizeof (fd_mask) * NBBY)	/* bits per mask */
1210Sstevel@tonic-gate #endif
1220Sstevel@tonic-gate #define	FD_NFDBITS	(sizeof (fds_mask) * _NBBY)	/* bits per mask */
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #define	__howmany(__x, __y)	(((__x)+((__y)-1))/(__y))
1250Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1260Sstevel@tonic-gate #ifndef	howmany
1270Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
1280Sstevel@tonic-gate #endif
1290Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1320Sstevel@tonic-gate typedef	struct fd_set {
1330Sstevel@tonic-gate #else
1340Sstevel@tonic-gate typedef	struct __fd_set {
1350Sstevel@tonic-gate #endif
1360Sstevel@tonic-gate 	long	fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
1370Sstevel@tonic-gate } fd_set;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate #define	FD_SET(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
1400Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS)))
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #define	FD_CLR(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
1430Sstevel@tonic-gate 				    ~(1ul << ((__n) % FD_NFDBITS)))
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate #define	FD_ISSET(__n, __p)	(((__p)->fds_bits[(__n)/FD_NFDBITS] & \
1460Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS))) != 0l)
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate #ifdef _KERNEL
1490Sstevel@tonic-gate #define	FD_ZERO(p)	bzero((p), sizeof (*(p)))
1500Sstevel@tonic-gate #else
1510Sstevel@tonic-gate #define	FD_ZERO(__p)    (void) memset((__p), 0, sizeof (*(__p)))
1520Sstevel@tonic-gate #endif /* _KERNEL */
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate #ifndef	_KERNEL
1550Sstevel@tonic-gate #ifdef	__STDC__
1560Sstevel@tonic-gate extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
1570Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD);
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
1600Sstevel@tonic-gate extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
1610Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD,
1620Sstevel@tonic-gate 	const sigset_t *_RESTRICT_KYWD);
1630Sstevel@tonic-gate #endif
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #else
1660Sstevel@tonic-gate extern int select();
1670Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
1680Sstevel@tonic-gate extern int pselect();
1690Sstevel@tonic-gate #endif
1700Sstevel@tonic-gate #endif	/* __STDC__ */
1710Sstevel@tonic-gate #endif	/* _KERNEL */
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate #ifdef	__cplusplus
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate #endif
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate #endif	/* _SYS_SELECT_H */
178