select.h revision 5bc78c8bcd0c1e634c04029309ede3ec05f2d424
1a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project/* 2a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 3a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * All rights reserved. 4a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * 5a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * Redistribution and use in source and binary forms, with or without 6a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * modification, are permitted provided that the following conditions 7a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * are met: 8a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * * Redistributions of source code must retain the above copyright 9a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * notice, this list of conditions and the following disclaimer. 10d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross * * Redistributions in binary form must reproduce the above copyright 11a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * notice, this list of conditions and the following disclaimer in 12a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * the documentation and/or other materials provided with the 13a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * distribution. 14a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * 15a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project * SUCH DAMAGE. 27a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project */ 28a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project 29a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#ifndef _SYS_SELECT_H_ 30a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define _SYS_SELECT_H_ 31a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project 32a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#include <sys/cdefs.h> 33a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#include <sys/types.h> 34a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project 35a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#include <linux/time.h> 36d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes#include <signal.h> 37460fa7033b17c49e3e6fdaee49eb6d7d666e16d9Ben Cheng 38a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project__BEGIN_DECLS 39a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project 40a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define FD_SETSIZE 1024 41a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define NFDBITS (8 * sizeof(unsigned long)) 42a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define __FDSET_LONGS (FD_SETSIZE/NFDBITS) 43a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project 44a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projecttypedef struct { 454e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project unsigned long fds_bits[__FDSET_LONGS]; 464e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project} fd_set; 474e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project 484e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project#define __FDELT(fd) ((fd) / NFDBITS) 49d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross#define __FDMASK(fd) (1UL << ((fd) % NFDBITS)) 50988ff8ff9fb8bb3394d5571ce088b23dc828edb5Raghu Gandham#define __FDS_BITS(set) (__BIONIC_CAST(static_cast, fd_set*, set)->fds_bits) 51d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes 524e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project/* Inline loop so we don't have to declare memset. */ 534e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project#define FD_ZERO(set) \ 54a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham do { \ 55a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham size_t __i; \ 56d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross for (__i = 0; __i < __FDSET_LONGS; ++__i) { \ 57a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham (set)->fds_bits[__i] = 0; \ 58d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes } \ 59a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham } while (0) 60c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjo 61c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjovoid __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 62b969b5a32a3924412b3584a2ab606ff64a3c4203David 'Digit' Turnervoid __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 630e772872090ea703a24e3afbfa1eb5abcace7f32Raghu Gandhamint __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); 64c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjo 65c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjo#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= __ANDROID_API_L__ 66a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set)) 67a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set)) 68a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set)) 69d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross#else 70d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross#define FD_CLR(fd, set) (__FDS_BITS(set)[__FDELT(fd)] &= ~__FDMASK(fd)) 718bea2b6faca554a145bdafc6f3afafec1f3120b6Ben Cheng#define FD_SET(fd, set) (__FDS_BITS(set)[__FDELT(fd)] |= __FDMASK(fd)) 728bea2b6faca554a145bdafc6f3afafec1f3120b6Ben Cheng#define FD_ISSET(fd, set) ((__FDS_BITS(set)[__FDELT(fd)] & __FDMASK(fd)) != 0) 738bea2b6faca554a145bdafc6f3afafec1f3120b6Ben Cheng#endif /* defined(__BIONIC_FORTIFY) && __ANDROID_API >= 21 */ 74d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross 75d1973ca51325393f304e82a4d79874f33e54ac16Colin Crossint select(int, fd_set*, fd_set*, fd_set*, struct timeval*); 76a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectint pselect(int, fd_set*, fd_set*, fd_set*, const struct timespec*, const sigset_t*); 77a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project 78a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project__END_DECLS 7982fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham 8082fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham#endif /* _SYS_SELECT_H_ */ 8182fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham