UbixOS V2  2.0
select.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _SYS_SELECT_H
30 #define _SYS_SELECT_H
31 
32 #include <sys/cdefs.h>
33 #include <sys/_types.h>
34 #include <sys/_timespec.h>
35 #include <sys/_timeval.h>
36 
37 #include <sys/_sigset.h>
38 
39 typedef unsigned long __fd_mask;
41 
42 #ifndef _SIGSET_T_DECLARED
43 #define _SIGSET_T_DECLARED
45 #endif
46 
47 /*
48  * Select uses bit masks of file descriptors in longs. These macros
49  * manipulate such bit fields (the filesystem macros use chars).
50  * FD_SETSIZE may be defined by the user, but the default here should
51  * be enough for most uses.
52  */
53 #ifndef FD_SETSIZE
54 #define FD_SETSIZE 1024
55 #endif
56 
57 #define _NFDBITS (sizeof(__fd_mask) * 8) /* bits per mask */
58 #define NFDBITS _NFDBITS
59 
60 #ifndef _howmany
61 #define _howmany(x, y) (((x) + ((y) - 1)) / (y))
62 #endif
63 
64 typedef struct fd_set {
66 } fd_set;
67 
68 #define fds_bits __fds_bits
69 
70 #define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS))
71 #define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
72 #define FD_COPY(f, t) (void)(*(t) = *(f))
73 #define FD_ISSET(n, p) (((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0)
74 #define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
75 #define FD_ZERO(p) do { \
76  fd_set *_p; \
77  __size_t _n; \
78  \
79  _p = (p); \
80  _n = _howmany(FD_SETSIZE, _NFDBITS); \
81  while (_n > 0) \
82  _p->__fds_bits[--_n] = 0; \
83 } while (0)
84 
85 #ifndef _KERNEL
86 
89 
90 #ifndef _SELECT_DECLARED
91 #define _SELECT_DECLARED
92 /* XXX missing restrict type-qualifier */
93 int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
94 #endif
96 #endif /* !_KERNEL */
97 
98 
99 
100 #endif /* END _SYS_SELECT_H */
FD_SETSIZE
#define FD_SETSIZE
Definition: select.h:54
_timespec.h
__fd_mask
unsigned long __fd_mask
Definition: select.h:39
_howmany
#define _howmany(x, y)
Definition: select.h:61
fd_set
Definition: select.h:64
_NFDBITS
#define _NFDBITS
Definition: select.h:57
sigset_t
__sigset_t sigset_t
Definition: select.h:44
__END_DECLS
#define __END_DECLS
Definition: assert.h:47
fd_set::__fds_bits
__fd_mask __fds_bits[(((1024)+(((sizeof(__fd_mask) *8)) - 1))/((sizeof(__fd_mask) *8)))]
Definition: select.h:65
__sigset
Definition: _sigset.h:42
_timeval.h
__restrict
#define __restrict
Definition: cdefs.h:435
_types.h
_sigset.h
__BEGIN_DECLS
#define __BEGIN_DECLS
Definition: assert.h:46
fd_mask
__fd_mask fd_mask
Definition: select.h:40
timeval
Definition: _timeval.h:17
fd_set
struct fd_set fd_set
cdefs.h
select
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
timespec
Definition: _timespec.h:11
pselect
__BEGIN_DECLS int pselect(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict)