1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 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 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _SYS_SELECT_H_ 30 #define _SYS_SELECT_H_ 31 32 #include <sys/cdefs.h> 33 #include <sys/types.h> 34 35 #include <linux/time.h> 36 #include <signal.h> 37 38 __BEGIN_DECLS 39 40 typedef unsigned long fd_mask; 41 42 #define FD_SETSIZE 1024 43 #define NFDBITS (8 * sizeof(fd_mask)) 44 45 typedef struct { 46 fd_mask fds_bits[FD_SETSIZE/NFDBITS]; 47 } fd_set; 48 49 #define __FDELT(fd) ((fd) / NFDBITS) 50 #define __FDMASK(fd) (1UL << ((fd) % NFDBITS)) 51 #define __FDS_BITS(type,set) (__BIONIC_CAST(static_cast, type, set)->fds_bits) 52 53 /* Inline loop so we don't have to declare memset. */ 54 #define FD_ZERO(set) \ 55 do { \ 56 size_t __i; \ 57 for (__i = 0; __i < sizeof(fd_set)/sizeof(fd_mask); ++__i) { \ 58 (set)->fds_bits[__i] = 0; \ 59 } \ 60 } while (0) 61 62 void __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 63 void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 64 int __FD_ISSET_chk(int, const fd_set*, size_t) __INTRODUCED_IN(21); 65 66 #define __FD_CLR(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] &= ~__FDMASK(fd)) 67 #define __FD_SET(fd, set) (__FDS_BITS(fd_set*,set)[__FDELT(fd)] |= __FDMASK(fd)) 68 #define __FD_ISSET(fd, set) ((__FDS_BITS(const fd_set*,set)[__FDELT(fd)] & __FDMASK(fd)) != 0) 69 70 71 #if __ANDROID_API__ >= __ANDROID_API_L__ 72 #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set)) 73 #define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set)) 74 #define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set)) 75 #else 76 #define FD_CLR(fd, set) __FD_CLR(fd, set) 77 #define FD_SET(fd, set) __FD_SET(fd, set) 78 #define FD_ISSET(fd, set) __FD_ISSET(fd, set) 79 #endif /* __ANDROID_API >= 21 */ 80 81 int select(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, struct timeval* __timeout); 82 int pselect(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset_t* __mask); 83 int pselect64(int __fd_count, fd_set* __read_fds, fd_set* __write_fds, fd_set* __exception_fds, const struct timespec* __timeout, const sigset64_t* __mask) __INTRODUCED_IN(28); 84 85 __END_DECLS 86 87 #endif 88