1 /* 2 Copyright (c) 1982, 1986, 1993 3 The Regents of the University of California. All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 1. Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 2. Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 3. Neither the name of the University nor the names of its contributors 14 may be used to endorse or promote products derived from this software 15 without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 SUCH DAMAGE. 28 */ 29 30 #ifndef _SYS__SELECT_H 31 #define _SYS__SELECT_H 32 33 _BEGIN_STD_C 34 35 # define _SYS_TYPES_FD_SET 36 /* 37 * Select uses bit masks of file descriptors in longs. 38 * These macros manipulate such bit fields (the filesystem macros use chars). 39 * FD_SETSIZE may be defined by the user, but the default here 40 * should be enough for most uses. 41 */ 42 #ifndef FD_SETSIZE 43 # if defined(__rtems__) 44 # define FD_SETSIZE 256 45 # else 46 # define FD_SETSIZE 64 47 # endif 48 #endif 49 50 typedef unsigned long __fd_mask; 51 #if __BSD_VISIBLE 52 typedef __fd_mask fd_mask; 53 #endif 54 55 #define __NFDBITS ((int)sizeof(__fd_mask) * 8) /* bits per mask */ 56 #define __FD_ARRAY_SIZE ((FD_SETSIZE + __NFDBITS - 1) / __NFDBITS) 57 #if __BSD_VISIBLE 58 #define NFDBITS __NFDBITS 59 #endif 60 61 typedef struct fd_set { 62 __fd_mask __fds_bits[__FD_ARRAY_SIZE]; 63 } fd_set; 64 65 #define __fdset_mask(n) ((__fd_mask)1 << ((n) % __NFDBITS)) 66 #define FD_CLR(n, p) ((p)->__fds_bits[(n)/__NFDBITS] &= ~__fdset_mask(n)) 67 #if __BSD_VISIBLE 68 #define FD_COPY(f, t) (void)(*(t) = *(f)) 69 #endif 70 #define FD_ISSET(n, p) (((p)->__fds_bits[(n)/__NFDBITS] & __fdset_mask(n)) != 0) 71 #define FD_SET(n, p) ((p)->__fds_bits[(n)/__NFDBITS] |= __fdset_mask(n)) 72 #define FD_ZERO(p) do { \ 73 fd_set *__p = (p); \ 74 __size_t __i; \ 75 for (__i = 0; __i < __FD_ARRAY_SIZE; __i++) \ 76 __p->__fds_bits[__i] = 0; \ 77 } while (0) 78 79 int select (int __n, fd_set *__readfds, fd_set *__writefds, 80 fd_set *__exceptfds, struct timeval *__timeout); 81 82 _END_STD_C 83 84 #endif /* sys/_select.h */ 85