1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 24 * 25 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 30 /* All Rights Reserved */ 31 32 /* 33 * University Copyright- Copyright (c) 1982, 1986, 1988 34 * The Regents of the University of California 35 * All Rights Reserved 36 * 37 * University Acknowledgment- Portions of this document are derived from 38 * software developed by the University of California, Berkeley, and its 39 * contributors. 40 */ 41 42 #ifndef _SYS_SELECT_H 43 #define _SYS_SELECT_H 44 45 #include <sys/feature_tests.h> 46 47 #ifndef _KERNEL 48 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 49 #include <sys/time_impl.h> 50 #endif 51 #include <sys/time.h> 52 #endif /* _KERNEL */ 53 54 #ifdef __cplusplus 55 extern "C" { 56 #endif 57 58 59 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 60 /* 61 * The sigset_t type is defined in <sys/signal.h> and duplicated 62 * in <sys/ucontext.h> as a result of XPG4v2 requirements. XPG6 63 * now allows the visibility of signal.h in this header, however 64 * an order of inclusion problem occurs as a result of inclusion 65 * of <sys/select.h> in <signal.h> under certain conditions. 66 * Rather than include <sys/signal.h> here, we've duplicated 67 * the sigset_t type instead. This type is required for the XPG6 68 * introduced pselect() function also declared in this header. 69 */ 70 #ifndef _SIGSET_T 71 #define _SIGSET_T 72 typedef struct { /* signal set type */ 73 unsigned int __sigbits[4]; 74 } sigset_t; 75 #endif /* _SIGSET_T */ 76 77 #endif /* #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */ 78 79 /* 80 * Select uses bit masks of file descriptors in longs. 81 * These macros manipulate such bit fields. 82 * FD_SETSIZE may be defined by the user, but the default here 83 * should be >= NOFILE (param.h). 84 */ 85 #ifndef FD_SETSIZE 86 #ifdef _LP64 87 #define FD_SETSIZE 65536 88 #else 89 #define FD_SETSIZE 1024 90 #endif /* _LP64 */ 91 #elif FD_SETSIZE > 1024 && !defined(_LP64) 92 #ifdef __PRAGMA_REDEFINE_EXTNAME 93 #pragma redefine_extname select select_large_fdset 94 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 95 #pragma redefine_extname pselect pselect_large_fdset 96 #endif 97 #else /* __PRAGMA_REDEFINE_EXTNAME */ 98 #define select select_large_fdset 99 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 100 #define pselect pselect_large_fdset 101 #endif 102 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 103 #endif /* FD_SETSIZE */ 104 105 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 106 typedef long fd_mask; 107 #endif 108 typedef long fds_mask; 109 110 /* 111 * The value of _NBBY needs to be consistant with the value 112 * of NBBY in <sys/param.h>. 113 */ 114 #define _NBBY 8 115 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 116 #ifndef NBBY /* number of bits per byte */ 117 #define NBBY _NBBY 118 #endif 119 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 120 121 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 122 #define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ 123 #endif 124 #define FD_NFDBITS (sizeof (fds_mask) * _NBBY) /* bits per mask */ 125 126 #define __howmany(__x, __y) (((__x)+((__y)-1))/(__y)) 127 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 128 #ifndef howmany 129 #define howmany(x, y) (((x)+((y)-1))/(y)) 130 #endif 131 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */ 132 133 #if !defined(_XPG4_2) || defined(__EXTENSIONS__) 134 typedef struct fd_set { 135 #else 136 typedef struct __fd_set { 137 #endif 138 long fds_bits[__howmany(FD_SETSIZE, FD_NFDBITS)]; 139 } fd_set; 140 141 #define FD_SET(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] |= \ 142 (1ul << ((__n) % FD_NFDBITS))) 143 144 #define FD_CLR(__n, __p) ((__p)->fds_bits[(__n)/FD_NFDBITS] &= \ 145 ~(1ul << ((__n) % FD_NFDBITS))) 146 147 #define FD_ISSET(__n, __p) (((__p)->fds_bits[(__n)/FD_NFDBITS] & \ 148 (1ul << ((__n) % FD_NFDBITS))) != 0l) 149 150 #ifdef _KERNEL 151 #define FD_ZERO(p) bzero((p), sizeof (*(p))) 152 #else 153 #define FD_ZERO(__p) (void) memset((__p), 0, sizeof (*(__p))) 154 #endif /* _KERNEL */ 155 156 #ifndef _KERNEL 157 extern int select(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD, 158 fd_set *_RESTRICT_KYWD, struct timeval *_RESTRICT_KYWD); 159 160 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__) 161 extern int pselect(int, fd_set *_RESTRICT_KYWD, fd_set *_RESTRICT_KYWD, 162 fd_set *_RESTRICT_KYWD, const struct timespec *_RESTRICT_KYWD, 163 const sigset_t *_RESTRICT_KYWD); 164 #endif 165 166 #endif /* _KERNEL */ 167 168 #ifdef __cplusplus 169 } 170 #endif 171 172 #endif /* _SYS_SELECT_H */