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 * 25*b819cea2SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 26*b819cea2SGordon 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 49*b819cea2SGordon 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> 54*b819cea2SGordon 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 857c478bd9Sstevel@tonic-gate * should be >= NOFILE (param.h). 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate #ifndef FD_SETSIZE 887c478bd9Sstevel@tonic-gate #ifdef _LP64 897c478bd9Sstevel@tonic-gate #define FD_SETSIZE 65536 907c478bd9Sstevel@tonic-gate #else 917c478bd9Sstevel@tonic-gate #define FD_SETSIZE 1024 927c478bd9Sstevel@tonic-gate #endif /* _LP64 */ 937c478bd9Sstevel@tonic-gate #elif FD_SETSIZE > 1024 && !defined(_LP64) 947c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME 957c478bd9Sstevel@tonic-gate #pragma redefine_extname select select_large_fdset 967c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 977c478bd9Sstevel@tonic-gate #pragma redefine_extname pselect pselect_large_fdset 987c478bd9Sstevel@tonic-gate #endif 997c478bd9Sstevel@tonic-gate #else /* __PRAGMA_REDEFINE_EXTNAME */ 1007c478bd9Sstevel@tonic-gate #define select select_large_fdset 1017c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 1027c478bd9Sstevel@tonic-gate #define pselect pselect_large_fdset 1037c478bd9Sstevel@tonic-gate #endif 1047c478bd9Sstevel@tonic-gate #endif /* __PRAGMA_REDEFINE_EXTNAME */ 1057c478bd9Sstevel@tonic-gate #endif /* FD_SETSIZE */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1087c478bd9Sstevel@tonic-gate typedef long fd_mask; 1097c478bd9Sstevel@tonic-gate #endif 1107c478bd9Sstevel@tonic-gate typedef long fds_mask; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * The value of _NBBY needs to be consistant with the value 1147c478bd9Sstevel@tonic-gate * of NBBY in <sys/param.h>. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate #define _NBBY 8 1177c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1187c478bd9Sstevel@tonic-gate #ifndef NBBY /* number of bits per byte */ 1197c478bd9Sstevel@tonic-gate #define NBBY _NBBY 1207c478bd9Sstevel@tonic-gate #endif 1217c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1247c478bd9Sstevel@tonic-gate #define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ 1257c478bd9Sstevel@tonic-gate #endif 1267c478bd9Sstevel@tonic-gate #define FD_NFDBITS (sizeof (fds_mask) * _NBBY) /* bits per mask */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate #define __howmany(__x, __y) (((__x)+((__y)-1))/(__y)) 1297c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1307c478bd9Sstevel@tonic-gate #ifndef howmany 1317c478bd9Sstevel@tonic-gate #define howmany(x, y) (((x)+((y)-1))/(y)) 1327c478bd9Sstevel@tonic-gate #endif 1337c478bd9Sstevel@tonic-gate #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 1367c478bd9Sstevel@tonic-gate typedef struct fd_set { 1377c478bd9Sstevel@tonic-gate #else 1387c478bd9Sstevel@tonic-gate typedef struct __fd_set { 1397c478bd9Sstevel@tonic-gate #endif 1407c478bd9Sstevel@tonic-gate long fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)]; 1417c478bd9Sstevel@tonic-gate } fd_set; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #define FD_SET(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] |= \ 1447c478bd9Sstevel@tonic-gate (1ul << ((__n) % FD_NFDBITS))) 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #define FD_CLR(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] &= \ 1477c478bd9Sstevel@tonic-gate ~(1ul << ((__n) % FD_NFDBITS))) 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #define FD_ISSET(__n, __p) (((__p)->fds_bits[(__n)/FD_NFDBITS] & \ 1507c478bd9Sstevel@tonic-gate (1ul << ((__n) % FD_NFDBITS))) != 0l) 1517c478bd9Sstevel@tonic-gate 152*b819cea2SGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL) 1537c478bd9Sstevel@tonic-gate #define FD_ZERO(p) bzero((p), sizeof (*(p))) 1547c478bd9Sstevel@tonic-gate #else 1557c478bd9Sstevel@tonic-gate #define FD_ZERO(__p) (void) memset((__p), 0, sizeof (*(__p))) 1567c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1577c478bd9Sstevel@tonic-gate 158*b819cea2SGordon Ross #if !defined(_KERNEL) && !defined(_FAKE_KERNEL) 1597c478bd9Sstevel@tonic-gate extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD, 1607c478bd9Sstevel@tonic-gate fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD); 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 1637c478bd9Sstevel@tonic-gate extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD, 1647c478bd9Sstevel@tonic-gate fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD, 1657c478bd9Sstevel@tonic-gate const sigset_t *_RESTRICT_KYWD); 1667c478bd9Sstevel@tonic-gate #endif 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate #endif 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate #endif /* _SYS_SELECT_H */ 175