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