xref: /titanic_52/usr/src/uts/common/sys/select.h (revision bdf0047c9427cca40961a023475891c898579c37)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*bdf0047cSRoger A. Faulkner  * Common Development and Distribution License (the "License").
6*bdf0047cSRoger A. Faulkner  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*bdf0047cSRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
23*bdf0047cSRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifndef _SYS_SELECT_H
417c478bd9Sstevel@tonic-gate #define	_SYS_SELECT_H
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifndef _KERNEL
467c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
477c478bd9Sstevel@tonic-gate #include <sys/time_impl.h>
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate #include <sys/time.h>
507c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
537c478bd9Sstevel@tonic-gate extern "C" {
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * The sigset_t type is defined in <sys/signal.h> and duplicated
607c478bd9Sstevel@tonic-gate  * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
617c478bd9Sstevel@tonic-gate  * now allows the visibility of signal.h in this header, however
627c478bd9Sstevel@tonic-gate  * an order of inclusion problem occurs as a result of inclusion
637c478bd9Sstevel@tonic-gate  * of <sys/select.h> in <signal.h> under certain conditions.
647c478bd9Sstevel@tonic-gate  * Rather than include <sys/signal.h> here, we've duplicated
657c478bd9Sstevel@tonic-gate  * the sigset_t type instead. This type is required for the XPG6
667c478bd9Sstevel@tonic-gate  * introduced pselect() function also declared in this header.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate #ifndef	_SIGSET_T
697c478bd9Sstevel@tonic-gate #define	_SIGSET_T
707c478bd9Sstevel@tonic-gate typedef struct {		/* signal set type */
717c478bd9Sstevel@tonic-gate 	unsigned int	__sigbits[4];
727c478bd9Sstevel@tonic-gate } sigset_t;
737c478bd9Sstevel@tonic-gate #endif  /* _SIGSET_T */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Select uses bit masks of file descriptors in longs.
797c478bd9Sstevel@tonic-gate  * These macros manipulate such bit fields.
807c478bd9Sstevel@tonic-gate  * FD_SETSIZE may be defined by the user, but the default here
817c478bd9Sstevel@tonic-gate  * should be >= NOFILE (param.h).
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #ifndef	FD_SETSIZE
847c478bd9Sstevel@tonic-gate #ifdef _LP64
857c478bd9Sstevel@tonic-gate #define	FD_SETSIZE	65536
867c478bd9Sstevel@tonic-gate #else
877c478bd9Sstevel@tonic-gate #define	FD_SETSIZE	1024
887c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
897c478bd9Sstevel@tonic-gate #elif FD_SETSIZE > 1024 && !defined(_LP64)
907c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
917c478bd9Sstevel@tonic-gate #pragma	redefine_extname	select	select_large_fdset
927c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
937c478bd9Sstevel@tonic-gate #pragma	redefine_extname	pselect	pselect_large_fdset
947c478bd9Sstevel@tonic-gate #endif
957c478bd9Sstevel@tonic-gate #else	/* __PRAGMA_REDEFINE_EXTNAME */
967c478bd9Sstevel@tonic-gate #define	select	select_large_fdset
977c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
987c478bd9Sstevel@tonic-gate #define	pselect	pselect_large_fdset
997c478bd9Sstevel@tonic-gate #endif
1007c478bd9Sstevel@tonic-gate #endif	/* __PRAGMA_REDEFINE_EXTNAME */
1017c478bd9Sstevel@tonic-gate #endif	/* FD_SETSIZE */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1047c478bd9Sstevel@tonic-gate typedef	long	fd_mask;
1057c478bd9Sstevel@tonic-gate #endif
1067c478bd9Sstevel@tonic-gate typedef	long	fds_mask;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  *  The value of _NBBY needs to be consistant with the value
1107c478bd9Sstevel@tonic-gate  *  of NBBY in <sys/param.h>.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #define	_NBBY 8
1137c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1147c478bd9Sstevel@tonic-gate #ifndef NBBY		/* number of bits per byte */
1157c478bd9Sstevel@tonic-gate #define	NBBY _NBBY
1167c478bd9Sstevel@tonic-gate #endif
1177c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1207c478bd9Sstevel@tonic-gate #define	NFDBITS		(sizeof (fd_mask) * NBBY)	/* bits per mask */
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate #define	FD_NFDBITS	(sizeof (fds_mask) * _NBBY)	/* bits per mask */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #define	__howmany(__x, __y)	(((__x)+((__y)-1))/(__y))
1257c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1267c478bd9Sstevel@tonic-gate #ifndef	howmany
1277c478bd9Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1327c478bd9Sstevel@tonic-gate typedef	struct fd_set {
1337c478bd9Sstevel@tonic-gate #else
1347c478bd9Sstevel@tonic-gate typedef	struct __fd_set {
1357c478bd9Sstevel@tonic-gate #endif
1367c478bd9Sstevel@tonic-gate 	long	fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
1377c478bd9Sstevel@tonic-gate } fd_set;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #define	FD_SET(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
1407c478bd9Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS)))
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	FD_CLR(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
1437c478bd9Sstevel@tonic-gate 				    ~(1ul << ((__n) % FD_NFDBITS)))
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #define	FD_ISSET(__n, __p)	(((__p)->fds_bits[(__n)/FD_NFDBITS] & \
1467c478bd9Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS))) != 0l)
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1497c478bd9Sstevel@tonic-gate #define	FD_ZERO(p)	bzero((p), sizeof (*(p)))
1507c478bd9Sstevel@tonic-gate #else
1517c478bd9Sstevel@tonic-gate #define	FD_ZERO(__p)    (void) memset((__p), 0, sizeof (*(__p)))
1527c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #ifndef	_KERNEL
1557c478bd9Sstevel@tonic-gate #ifdef	__STDC__
1567c478bd9Sstevel@tonic-gate extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
1577c478bd9Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
1607c478bd9Sstevel@tonic-gate extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
1617c478bd9Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD,
1627c478bd9Sstevel@tonic-gate 	const sigset_t *_RESTRICT_KYWD);
1637c478bd9Sstevel@tonic-gate #endif
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #else
1667c478bd9Sstevel@tonic-gate extern int select();
1677c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
1687c478bd9Sstevel@tonic-gate extern int pselect();
1697c478bd9Sstevel@tonic-gate #endif
1707c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
1717c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate #endif
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #endif	/* _SYS_SELECT_H */
178