Back to index

glibc  2.9
select.h
Go to the documentation of this file.
00001 /* `fd_set' type and related macros, and `select'/`pselect' declarations.
00002    Copyright (C) 1996,97,98,99,2000,01,02,2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /*     POSIX 1003.1g: 6.2 Select from File Descriptor Sets <sys/select.h>  */
00021 
00022 #ifndef _SYS_SELECT_H
00023 #define _SYS_SELECT_H       1
00024 
00025 #include <features.h>
00026 
00027 /* Get definition of needed basic types.  */
00028 #include <bits/types.h>
00029 
00030 /* Get __FD_* definitions.  */
00031 #include <bits/select.h>
00032 
00033 /* Get __sigset_t.  */
00034 #include <bits/sigset.h>
00035 
00036 #ifndef __sigset_t_defined
00037 # define __sigset_t_defined
00038 typedef __sigset_t sigset_t;
00039 #endif
00040 
00041 /* Get definition of timer specification structures.  */
00042 #define __need_time_t
00043 #define __need_timespec
00044 #include <time.h>
00045 #define __need_timeval
00046 #include <bits/time.h>
00047 
00048 #ifndef __suseconds_t_defined
00049 typedef __suseconds_t suseconds_t;
00050 # define __suseconds_t_defined
00051 #endif
00052 
00053 
00054 /* The fd_set member is required to be an array of longs.  */
00055 typedef long int __fd_mask;
00056 
00057 /* Some versions of <linux/posix_types.h> define these macros.  */
00058 #undef __NFDBITS
00059 #undef __FDELT
00060 #undef __FDMASK
00061 /* It's easier to assume 8-bit bytes than to get CHAR_BIT.  */
00062 #define __NFDBITS    (8 * sizeof (__fd_mask))
00063 #define       __FDELT(d)    ((d) / __NFDBITS)
00064 #define       __FDMASK(d)   ((__fd_mask) 1 << ((d) % __NFDBITS))
00065 
00066 /* fd_set for select and pselect.  */
00067 typedef struct
00068   {
00069     /* XPG4.2 requires this member name.  Otherwise avoid the name
00070        from the global namespace.  */
00071 #ifdef __USE_XOPEN
00072     __fd_mask fds_bits[__FD_SETSIZE / __NFDBITS];
00073 # define __FDS_BITS(set) ((set)->fds_bits)
00074 #else
00075     __fd_mask __fds_bits[__FD_SETSIZE / __NFDBITS];
00076 # define __FDS_BITS(set) ((set)->__fds_bits)
00077 #endif
00078   } fd_set;
00079 
00080 /* Maximum number of file descriptors in `fd_set'.  */
00081 #define       FD_SETSIZE           __FD_SETSIZE
00082 
00083 #ifdef __USE_MISC
00084 /* Sometimes the fd_set member is assumed to have this type.  */
00085 typedef __fd_mask fd_mask;
00086 
00087 /* Number of bits per word of `fd_set' (some code assumes this is 32).  */
00088 # define NFDBITS            __NFDBITS
00089 #endif
00090 
00091 
00092 /* Access macros for `fd_set'.  */
00093 #define       FD_SET(fd, fdsetp)   __FD_SET (fd, fdsetp)
00094 #define       FD_CLR(fd, fdsetp)   __FD_CLR (fd, fdsetp)
00095 #define       FD_ISSET(fd, fdsetp) __FD_ISSET (fd, fdsetp)
00096 #define       FD_ZERO(fdsetp)             __FD_ZERO (fdsetp)
00097 
00098 
00099 __BEGIN_DECLS
00100 
00101 /* Check the first NFDS descriptors each in READFDS (if not NULL) for read
00102    readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
00103    (if not NULL) for exceptional conditions.  If TIMEOUT is not NULL, time out
00104    after waiting the interval specified therein.  Returns the number of ready
00105    descriptors, or -1 for errors.
00106 
00107    This function is a cancellation point and therefore not marked with
00108    __THROW.  */
00109 extern int select (int __nfds, fd_set *__restrict __readfds,
00110                  fd_set *__restrict __writefds,
00111                  fd_set *__restrict __exceptfds,
00112                  struct timeval *__restrict __timeout);
00113 
00114 #ifdef __USE_XOPEN2K
00115 /* Same as above only that the TIMEOUT value is given with higher
00116    resolution and a sigmask which is been set temporarily.  This version
00117    should be used.
00118 
00119    This function is a cancellation point and therefore not marked with
00120    __THROW.  */
00121 extern int pselect (int __nfds, fd_set *__restrict __readfds,
00122                   fd_set *__restrict __writefds,
00123                   fd_set *__restrict __exceptfds,
00124                   const struct timespec *__restrict __timeout,
00125                   const __sigset_t *__restrict __sigmask);
00126 #endif
00127 
00128 __END_DECLS
00129 
00130 #endif /* sys/select.h */