xref: /illumos-gate/usr/src/uts/common/sys/select.h (revision 2209d3c8)
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
5bdf0047cSRoger A. Faulkner  * Common Development and Distribution License (the "License").
6bdf0047cSRoger 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  */
21bdf0047cSRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
23ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24ba3594baSGarrett D'Amore  *
25b819cea2SGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
26b819cea2SGordon Ross  *
27bdf0047cSRoger A. Faulkner  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
327c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
367c478bd9Sstevel@tonic-gate  * The Regents of the University of California
377c478bd9Sstevel@tonic-gate  * All Rights Reserved
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
407c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
417c478bd9Sstevel@tonic-gate  * contributors.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifndef _SYS_SELECT_H
457c478bd9Sstevel@tonic-gate #define	_SYS_SELECT_H
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
487c478bd9Sstevel@tonic-gate 
49b819cea2SGordon Ross #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
507c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
517c478bd9Sstevel@tonic-gate #include <sys/time_impl.h>
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate #include <sys/time.h>
54b819cea2SGordon Ross #endif /* !_KERNEL */
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
577c478bd9Sstevel@tonic-gate extern "C" {
587c478bd9Sstevel@tonic-gate #endif
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * The sigset_t type is defined in <sys/signal.h> and duplicated
647c478bd9Sstevel@tonic-gate  * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6
657c478bd9Sstevel@tonic-gate  * now allows the visibility of signal.h in this header, however
667c478bd9Sstevel@tonic-gate  * an order of inclusion problem occurs as a result of inclusion
677c478bd9Sstevel@tonic-gate  * of <sys/select.h> in <signal.h> under certain conditions.
687c478bd9Sstevel@tonic-gate  * Rather than include <sys/signal.h> here, we've duplicated
697c478bd9Sstevel@tonic-gate  * the sigset_t type instead. This type is required for the XPG6
707c478bd9Sstevel@tonic-gate  * introduced pselect() function also declared in this header.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #ifndef	_SIGSET_T
737c478bd9Sstevel@tonic-gate #define	_SIGSET_T
747c478bd9Sstevel@tonic-gate typedef struct {		/* signal set type */
757c478bd9Sstevel@tonic-gate 	unsigned int	__sigbits[4];
767c478bd9Sstevel@tonic-gate } sigset_t;
777c478bd9Sstevel@tonic-gate #endif  /* _SIGSET_T */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * Select uses bit masks of file descriptors in longs.
837c478bd9Sstevel@tonic-gate  * These macros manipulate such bit fields.
847c478bd9Sstevel@tonic-gate  * FD_SETSIZE may be defined by the user, but the default here
85*2209d3c8SRichard Lowe  * should be >= RLIM_FD_MAX.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate #ifndef	FD_SETSIZE
887c478bd9Sstevel@tonic-gate #define	FD_SETSIZE	65536
897c478bd9Sstevel@tonic-gate #endif	/* FD_SETSIZE */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
927c478bd9Sstevel@tonic-gate typedef	long	fd_mask;
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate typedef	long	fds_mask;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  *  The value of _NBBY needs to be consistant with the value
987c478bd9Sstevel@tonic-gate  *  of NBBY in <sys/param.h>.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate #define	_NBBY 8
1017c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1027c478bd9Sstevel@tonic-gate #ifndef NBBY		/* number of bits per byte */
1037c478bd9Sstevel@tonic-gate #define	NBBY _NBBY
1047c478bd9Sstevel@tonic-gate #endif
1057c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1087c478bd9Sstevel@tonic-gate #define	NFDBITS		(sizeof (fd_mask) * NBBY)	/* bits per mask */
1097c478bd9Sstevel@tonic-gate #endif
1107c478bd9Sstevel@tonic-gate #define	FD_NFDBITS	(sizeof (fds_mask) * _NBBY)	/* bits per mask */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #define	__howmany(__x, __y)	(((__x)+((__y)-1))/(__y))
1137c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
1147c478bd9Sstevel@tonic-gate #ifndef	howmany
1157c478bd9Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
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 typedef	struct fd_set {
1217c478bd9Sstevel@tonic-gate #else
1227c478bd9Sstevel@tonic-gate typedef	struct __fd_set {
1237c478bd9Sstevel@tonic-gate #endif
1247c478bd9Sstevel@tonic-gate 	long	fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)];
1257c478bd9Sstevel@tonic-gate } fd_set;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	FD_SET(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] |= \
1287c478bd9Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS)))
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	FD_CLR(__n, __p)	((__p)->fds_bits[(__n)/FD_NFDBITS] &= \
1317c478bd9Sstevel@tonic-gate 				    ~(1ul << ((__n) % FD_NFDBITS)))
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #define	FD_ISSET(__n, __p)	(((__p)->fds_bits[(__n)/FD_NFDBITS] & \
1347c478bd9Sstevel@tonic-gate 				    (1ul << ((__n) % FD_NFDBITS))) != 0l)
1357c478bd9Sstevel@tonic-gate 
136b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
1377c478bd9Sstevel@tonic-gate #define	FD_ZERO(p)	bzero((p), sizeof (*(p)))
1387c478bd9Sstevel@tonic-gate #else
1397c478bd9Sstevel@tonic-gate #define	FD_ZERO(__p)    (void) memset((__p), 0, sizeof (*(__p)))
1407c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1417c478bd9Sstevel@tonic-gate 
142b819cea2SGordon Ross #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
1437c478bd9Sstevel@tonic-gate extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
1447c478bd9Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
1477c478bd9Sstevel@tonic-gate extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD,
1487c478bd9Sstevel@tonic-gate 	fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD,
1497c478bd9Sstevel@tonic-gate 	const sigset_t *_RESTRICT_KYWD);
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate #endif
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #endif	/* _SYS_SELECT_H */
159