1 /* 2 * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ESP_SYS_SELECT_H__ 8 #define __ESP_SYS_SELECT_H__ 9 10 /* Newlib 2.2.0 does not provide sys/select.h, and fd_set is defined in sys/types.h */ 11 #include <sys/types.h> 12 #ifndef fd_set 13 #include_next <sys/select.h> 14 #else // fd_set 15 #include <sys/time.h> 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout); 22 23 #ifdef __cplusplus 24 } // extern "C" 25 #endif 26 27 #endif // fd_set 28 29 #if defined(FD_ISSET) || defined(FD_SET) || defined(FD_CLR) 30 #undef FD_SET 31 #undef FD_CLR 32 #undef FD_ISSET 33 34 #define __FD_SAFE_SET(n, code) do { if ((unsigned)(n) < FD_SETSIZE) { code; } } while(0) 35 #define __FD_SAFE_GET(n, code) (((unsigned)(n) < FD_SETSIZE) ? (code) : 0) 36 37 #define FD_SET(n, p) __FD_SAFE_SET(n, ((p)->fds_bits[(n) / NFDBITS] |= (1L << ((n) % NFDBITS)))) 38 #define FD_CLR(n, p) __FD_SAFE_SET(n, ((p)->fds_bits[(n) / NFDBITS] &= ~(1L << ((n) % NFDBITS)))) 39 #define FD_ISSET(n, p) __FD_SAFE_GET(n, ((p)->fds_bits[(n) / NFDBITS] & (1L << ((n) % NFDBITS)))) 40 #endif // FD_ISSET || FD_SET || FD_CLR 41 42 #endif //__ESP_SYS_SELECT_H__ 43