select.h

Go to the documentation of this file.
00001 /*-
00002  * Copyright (c) 1992, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 4. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  * $FreeBSD: src/sys/sys/select.h,v 1.19 2004/04/07 04:19:49 imp Exp $
00030  */
00031 
00032 #ifndef _SYS_SELECT_H_
00033 #define _SYS_SELECT_H_
00034 
00035 #include <sys/cdefs.h>
00036 #include <sys/_types.h>
00037 
00038 #include <sys/_sigset.h>
00039 #include <sys/_timeval.h>
00040 #include <sys/timespec.h>
00041 
00042 typedef unsigned long   __fd_mask;
00043 #if __BSD_VISIBLE
00044 typedef __fd_mask       fd_mask;
00045 #endif
00046 
00047 #ifndef _SIGSET_T_DECLARED
00048 #define _SIGSET_T_DECLARED
00049 typedef __sigset_t      sigset_t;
00050 #endif
00051 
00052 /*
00053  * Select uses bit masks of file descriptors in longs.  These macros
00054  * manipulate such bit fields (the filesystem macros use chars).
00055  * FD_SETSIZE may be defined by the user, but the default here should
00056  * be enough for most uses.
00057  */
00058 #ifndef FD_SETSIZE
00059 #define FD_SETSIZE      1024U
00060 #endif
00061 
00062 #define _NFDBITS        (sizeof(__fd_mask) * 8) /* bits per mask */
00063 #if __BSD_VISIBLE
00064 #define NFDBITS         _NFDBITS
00065 #endif
00066 
00067 #ifndef _howmany
00068 #define _howmany(x, y)  (((x) + ((y) - 1)) / (y))
00069 #endif
00070 
00071 typedef struct fd_set {
00072         __fd_mask       __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
00073 } fd_set;
00074 #if __BSD_VISIBLE
00075 #define fds_bits        __fds_bits
00076 #endif
00077 
00078 #define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS))
00079 #define FD_CLR(n, p)    ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
00080 #if __BSD_VISIBLE
00081 #define FD_COPY(f, t)   (void)(*(t) = *(f))
00082 #endif
00083 #define FD_ISSET(n, p)  ((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n))
00084 #define FD_SET(n, p)    ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
00085 #define FD_ZERO(p) do {                                 \
00086         fd_set *_p;                                     \
00087         __size_t _n;                                    \
00088                                                         \
00089         _p = (p);                                       \
00090         _n = _howmany(FD_SETSIZE, _NFDBITS);            \
00091         while (_n > 0)                                  \
00092                 _p->__fds_bits[--_n] = 0;               \
00093 } while (0)
00094 
00095 #ifndef _KERNEL
00096 
00097 __BEGIN_DECLS
00098 #ifndef _SELECT_DECLARED
00099 #define _SELECT_DECLARED
00100 /* XXX missing restrict type-qualifier */
00101 IMPORT_C int    select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
00102 #endif
00103 __END_DECLS
00104 #endif /* !_KERNEL */
00105 
00106 #endif /* _SYS_SELECT_H_ */

Copyright © Nokia Corporation 2001-2008
Back to top