11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * All rights reserved. 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met: 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Redistributions of source code must retain the above copyright 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Redistributions in binary form must reproduce the above copyright 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer in 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * the documentation and/or other materials provided with the 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * distribution. 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE. 271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 283503ce2177a56a8807887ee540abc68377483393Elliott Hughes 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _SYS_SELECT_H_ 301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _SYS_SELECT_H_ 311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 32db4990373232182a897e10663344c429f5d1b2d5Yabin Cui#include <sys/cdefs.h> 33db4990373232182a897e10663344c429f5d1b2d5Yabin Cui#include <sys/types.h> 341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 3516016df79f846d6d21266c3b1dce1e7c24dc4be1Josh Gao#include <linux/time.h> 3616016df79f846d6d21266c3b1dce1e7c24dc4be1Josh Gao#include <signal.h> 3716016df79f846d6d21266c3b1dce1e7c24dc4be1Josh Gao 381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__BEGIN_DECLS 391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 403503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_SETSIZE 1024 413503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define NFDBITS (8 * sizeof(unsigned long)) 423503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define __FDSET_LONGS (FD_SETSIZE/NFDBITS) 431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 44d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughestypedef struct { 45d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes unsigned long fds_bits[__FDSET_LONGS]; 46d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes} fd_set; 47d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes 483503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define __FDELT(fd) ((fd) / NFDBITS) 493503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define __FDMASK(fd) (1UL << ((fd) % NFDBITS)) 505470c183611737af5ec954984e4bdb5da8c99b73Elliott Hughes#define __FDS_BITS(set) (__BIONIC_CAST(static_cast, fd_set*, set)->fds_bits) 513503ce2177a56a8807887ee540abc68377483393Elliott Hughes 525038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes/* Inline loop so we don't have to declare memset. */ 535038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes#define FD_ZERO(set) \ 545038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes do { \ 555038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes size_t __i; \ 565038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes for (__i = 0; __i < __FDSET_LONGS; ++__i) { \ 575038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes (set)->fds_bits[__i] = 0; \ 585038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes } \ 595038b19cef207b526f9993951e4a04c8df91ce1dElliott Hughes } while (0) 607943df62f70f686b0c77532f6617b47255d75763Nick Kralevich 613b2096a9d6edd74622b94cacc76b77100f919b84Elliott Hughesvoid __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 623b2096a9d6edd74622b94cacc76b77100f919b84Elliott Hughesvoid __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 633b2096a9d6edd74622b94cacc76b77100f919b84Elliott Hughesint __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 64658727e111ed6dee7be5239494f0764f7b1b02f8Dan Albert 655bc78c8bcd0c1e634c04029309ede3ec05f2d424Elliott Hughes#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= __ANDROID_API_L__ 663503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set)) 673503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set)) 683503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set)) 697943df62f70f686b0c77532f6617b47255d75763Nick Kralevich#else 703503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_CLR(fd, set) (__FDS_BITS(set)[__FDELT(fd)] &= ~__FDMASK(fd)) 713503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_SET(fd, set) (__FDS_BITS(set)[__FDELT(fd)] |= __FDMASK(fd)) 723503ce2177a56a8807887ee540abc68377483393Elliott Hughes#define FD_ISSET(fd, set) ((__FDS_BITS(set)[__FDELT(fd)] & __FDMASK(fd)) != 0) 73299040420652498575ddfc7516a16ac5f835c132Dan Albert#endif /* defined(__BIONIC_FORTIFY) && __ANDROID_API >= 21 */ 7490201d5eca050414d50a433866ccb580415bb0d4Nick Kralevich 753b2096a9d6edd74622b94cacc76b77100f919b84Elliott Hughesint select(int, fd_set*, fd_set*, fd_set*, struct timeval*); 763b2096a9d6edd74622b94cacc76b77100f919b84Elliott Hughesint pselect(int, fd_set*, fd_set*, fd_set*, const struct timespec*, const sigset_t*); 771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__END_DECLS 791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _SYS_SELECT_H_ */ 81