TizenRT Libs&Environment  v2.0 M2
select.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/sys/select.h
20  *
21  * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
60 
63 #ifndef __INCLUDE_SYS_SELECT_H
64 #define __INCLUDE_SYS_SELECT_H
65 
66 /****************************************************************************
67  * Included Files
68  ****************************************************************************/
69 
70 #include <tinyara/config.h>
71 
72 #include <stdint.h>
73 #include <time.h>
74 
75 #if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0
76 
77 /****************************************************************************
78  * Pre-Processor Definitions
79  ****************************************************************************/
80 
81 /* Get the total number of descriptors that we will have to support */
82 
83 #define __SELECT_NDESCRIPTORS (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
84 
85 /* We will use a 32-bit bitsets to represent the set of descriptors. How
86  * many uint32_t's do we need to span all descriptors?
87  */
88 
89 #if __SELECT_NDESCRIPTORS <= 32
90 #define __SELECT_NUINT32 1
91 #elif __SELECT_NDESCRIPTORS <= 64
92 #define __SELECT_NUINT32 2
93 #elif __SELECT_NDESCRIPTORS <= 96
94 #define __SELECT_NUINT32 3
95 #elif __SELECT_NDESCRIPTORS <= 128
96 #define __SELECT_NUINT32 4
97 #elif __SELECT_NDESCRIPTORS <= 160
98 #define __SELECT_NUINT32 5
99 #elif __SELECT_NDESCRIPTORS <= 192
100 #define __SELECT_NUINT32 6
101 #elif __SELECT_NDESCRIPTORS <= 224
102 #define __SELECT_NUINT32 7
103 #elif __SELECT_NDESCRIPTORS <= 256
104 #define __SELECT_NUINT32 8
105 #else
106 #warning "Large fd_set needed"
107 #endif
108 
109 /****************************************************************************
110  * Type Definitions
111  ****************************************************************************/
112 
113 typedef struct fd_set {
114  uint8_t fd_bits[__SELECT_NUINT32 * 4];
115 } fd_set;
116 
117 /****************************************************************************
118  * Integration with LWIP
119  *
120  * select() can be defined in fs/vfs/fs_select.c or
121  * or in net/socket/bsd_socket_api.c when CONFIG_DISABLE_POLL=y
122  *
123  * in the second case LWIP implementation will be used with own declatations
124  *
125  ****************************************************************************/
126 
127 #if defined(CONFIG_DISABLE_POLL)
128 
129 #if !defined(CONFIG_NET_SOCKET)
130 /* #error Both system poll and network sockets are disabled */
131 #else
132 #include <net/lwip/sockets.h>
133 #endif
134 
135 #else
136 
137 /* Standard helper macros */
138 
139 #define FD_CLR(fd, set) ((set)->fd_bits[(fd)/8]) &= ~(1 << ((fd) & 7))
140 #define FD_SET(fd, set) ((set)->fd_bits[(fd)/8]) |= (1 << ((fd) & 7))
141 #define FD_ISSET(fd, set) ((set)->fd_bits[(fd)/8]) & (1 << ((fd) & 7))
142 #define FD_ZERO(set) memset(set, 0, sizeof(fd_set))
143 
144 #endif /* CONFIG_DISABLE_POLL */
145 
146 /****************************************************************************
147  * Public Function Prototypes
148  ****************************************************************************/
149 
150 #undef EXTERN
151 #if defined(__cplusplus)
152 #define EXTERN extern "C"
153 extern "C" {
154 #else
155 #define EXTERN extern
156 #endif
157 
166 EXTERN int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, FAR fd_set *exceptfds, FAR struct timeval *timeout);
167 
168 #undef EXTERN
169 #if defined(__cplusplus)
170 }
171 #endif
172 
173 #endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */
174 
175 #endif /* __INCLUDE_SYS_SELECT_H */
176 
Definition: select.h:113
uint8_t fd_bits[__SELECT_NUINT32 *4]
Definition: select.h:114
struct fd_set fd_set
EXTERN int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, FAR fd_set *exceptfds, FAR struct timeval *timeout)
synchronous I/O multiplexing
structure represents an elapsed time
Definition: time.h:168
#define __SELECT_NUINT32
Definition: select.h:90
#define EXTERN
Definition: select.h:155