| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* `fd_set' type and related macros, and `select'/`pselect' declarations. | 
|  | 2 | Copyright (C) 1996-2016 Free Software Foundation, Inc. | 
|  | 3 | This file is part of the GNU C Library. | 
|  | 4 |  | 
|  | 5 | The GNU C Library is free software; you can redistribute it and/or | 
|  | 6 | modify it under the terms of the GNU Lesser General Public | 
|  | 7 | License as published by the Free Software Foundation; either | 
|  | 8 | version 2.1 of the License, or (at your option) any later version. | 
|  | 9 |  | 
|  | 10 | The GNU C Library is distributed in the hope that it will be useful, | 
|  | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 13 | Lesser General Public License for more details. | 
|  | 14 |  | 
|  | 15 | You should have received a copy of the GNU Lesser General Public | 
|  | 16 | License along with the GNU C Library; if not, see | 
|  | 17 | <http://www.gnu.org/licenses/>.  */ | 
|  | 18 |  | 
|  | 19 | /*	POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h>  */ | 
|  | 20 |  | 
|  | 21 | #ifndef _SYS_SELECT_H | 
|  | 22 | #define _SYS_SELECT_H	1 | 
|  | 23 |  | 
|  | 24 | #include <features.h> | 
|  | 25 |  | 
|  | 26 | /* Get definition of needed basic types.  */ | 
|  | 27 | #include <bits/types.h> | 
|  | 28 |  | 
|  | 29 | /* Get __FD_* definitions.  */ | 
|  | 30 | #include <bits/select.h> | 
|  | 31 |  | 
|  | 32 | /* Get __sigset_t.  */ | 
|  | 33 | #include <bits/sigset.h> | 
|  | 34 |  | 
|  | 35 | #ifndef __sigset_t_defined | 
|  | 36 | # define __sigset_t_defined | 
|  | 37 | typedef __sigset_t sigset_t; | 
|  | 38 | #endif | 
|  | 39 |  | 
|  | 40 | /* Get definition of timer specification structures.  */ | 
|  | 41 | #define __need_time_t | 
|  | 42 | #define __need_timespec | 
|  | 43 | #include <time.h> | 
|  | 44 | #define __need_timeval | 
|  | 45 | #include <bits/time.h> | 
|  | 46 |  | 
|  | 47 | #ifndef __suseconds_t_defined | 
|  | 48 | typedef __suseconds_t suseconds_t; | 
|  | 49 | # define __suseconds_t_defined | 
|  | 50 | #endif | 
|  | 51 |  | 
|  | 52 |  | 
|  | 53 | /* The fd_set member is required to be an array of longs.  */ | 
|  | 54 | typedef long int __fd_mask; | 
|  | 55 |  | 
|  | 56 | /* Some versions of <linux/posix_types.h> define this macros.  */ | 
|  | 57 | #undef	__NFDBITS | 
|  | 58 | /* It's easier to assume 8-bit bytes than to get CHAR_BIT.  */ | 
|  | 59 | #define __NFDBITS	(8 * (int) sizeof (__fd_mask)) | 
|  | 60 | #define	__FD_ELT(d)	((d) / __NFDBITS) | 
|  | 61 | #define	__FD_MASK(d)	((__fd_mask) (1UL << ((d) % __NFDBITS))) | 
|  | 62 |  | 
|  | 63 | /* fd_set for select and pselect.  */ | 
|  | 64 | typedef struct | 
|  | 65 | { | 
|  | 66 | /* XPG4.2 requires this member name.  Otherwise avoid the name | 
|  | 67 | from the global namespace.  */ | 
|  | 68 | #ifdef __USE_XOPEN | 
|  | 69 | __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS]; | 
|  | 70 | # define __FDS_BITS(set) ((set)->fds_bits) | 
|  | 71 | #else | 
|  | 72 | __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS]; | 
|  | 73 | # define __FDS_BITS(set) ((set)->__fds_bits) | 
|  | 74 | #endif | 
|  | 75 | } fd_set; | 
|  | 76 |  | 
|  | 77 | /* Maximum number of file descriptors in `fd_set'.  */ | 
|  | 78 | #define	FD_SETSIZE		__FD_SETSIZE | 
|  | 79 |  | 
|  | 80 | #ifdef __USE_MISC | 
|  | 81 | /* Sometimes the fd_set member is assumed to have this type.  */ | 
|  | 82 | typedef __fd_mask fd_mask; | 
|  | 83 |  | 
|  | 84 | /* Number of bits per word of `fd_set' (some code assumes this is 32).  */ | 
|  | 85 | # define NFDBITS		__NFDBITS | 
|  | 86 | #endif | 
|  | 87 |  | 
|  | 88 |  | 
|  | 89 | /* Access macros for `fd_set'.  */ | 
|  | 90 | #define	FD_SET(fd, fdsetp)	__FD_SET (fd, fdsetp) | 
|  | 91 | #define	FD_CLR(fd, fdsetp)	__FD_CLR (fd, fdsetp) | 
|  | 92 | #define	FD_ISSET(fd, fdsetp)	__FD_ISSET (fd, fdsetp) | 
|  | 93 | #define	FD_ZERO(fdsetp)		__FD_ZERO (fdsetp) | 
|  | 94 |  | 
|  | 95 |  | 
|  | 96 | __BEGIN_DECLS | 
|  | 97 |  | 
|  | 98 | /* Check the first NFDS descriptors each in READFDS (if not NULL) for read | 
|  | 99 | readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS | 
|  | 100 | (if not NULL) for exceptional conditions.  If TIMEOUT is not NULL, time out | 
|  | 101 | after waiting the interval specified therein.  Returns the number of ready | 
|  | 102 | descriptors, or -1 for errors. | 
|  | 103 |  | 
|  | 104 | This function is a cancellation point and therefore not marked with | 
|  | 105 | __THROW.  */ | 
|  | 106 | extern int select (int __nfds, fd_set *__restrict __readfds, | 
|  | 107 | fd_set *__restrict __writefds, | 
|  | 108 | fd_set *__restrict __exceptfds, | 
|  | 109 | struct timeval *__restrict __timeout); | 
|  | 110 |  | 
|  | 111 | #ifdef __USE_XOPEN2K | 
|  | 112 | /* Same as above only that the TIMEOUT value is given with higher | 
|  | 113 | resolution and a sigmask which is been set temporarily.  This version | 
|  | 114 | should be used. | 
|  | 115 |  | 
|  | 116 | This function is a cancellation point and therefore not marked with | 
|  | 117 | __THROW.  */ | 
|  | 118 | extern int pselect (int __nfds, fd_set *__restrict __readfds, | 
|  | 119 | fd_set *__restrict __writefds, | 
|  | 120 | fd_set *__restrict __exceptfds, | 
|  | 121 | const struct timespec *__restrict __timeout, | 
|  | 122 | const __sigset_t *__restrict __sigmask); | 
|  | 123 | #endif | 
|  | 124 |  | 
|  | 125 |  | 
|  | 126 | /* Define some inlines helping to catch common problems.  */ | 
|  | 127 | #if __USE_FORTIFY_LEVEL > 0 && defined __GNUC__ | 
|  | 128 | # include <bits/select2.h> | 
|  | 129 | #endif | 
|  | 130 |  | 
|  | 131 | __END_DECLS | 
|  | 132 |  | 
|  | 133 | #endif /* sys/select.h */ |