Skip to content

Commit d1e5227

Browse files
aescolarDashingR
authored andcommitted
Revert "net: sockets: move select() implementation to zvfs"
This reverts commit 49ac191. PR zephyrproject-rtos#73978 introduced a regression. Unfortunately this PR cannot be reverted without reverting also Let's revert both PRs to stabilize main again towards the 3.7 release. For more details on the issue see zephyrproject-rtos#75205 Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent bb51dfe commit d1e5227

File tree

12 files changed

+82
-146
lines changed

12 files changed

+82
-146
lines changed

include/zephyr/net/socket_select.h

+14-28
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
* @{
2020
*/
2121

22-
#include <time.h>
23-
2422
#include <zephyr/toolchain.h>
2523
#include <zephyr/net/socket_types.h>
26-
#include <zephyr/sys/fdtable.h>
2724

2825
#ifdef __cplusplus
2926
extern "C" {
3027
#endif
3128

3229
/** Socket file descriptor set. */
33-
typedef struct zvfs_fd_set zsock_fd_set;
30+
typedef struct zsock_fd_set {
31+
uint32_t bitset[(CONFIG_ZVFS_OPEN_MAX + 31) / 32];
32+
} zsock_fd_set;
3433

3534
/**
3635
* @brief Legacy function to poll multiple sockets for events
@@ -48,16 +47,13 @@ typedef struct zvfs_fd_set zsock_fd_set;
4847
* it may conflict with generic POSIX ``select()`` function).
4948
* @endrst
5049
*/
51-
static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds,
52-
zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
53-
{
54-
struct timeval;
55-
56-
return zvfs_select(nfds, readfds, writefds, exceptfds, (struct timeval *)timeout);
57-
}
50+
__syscall int zsock_select(int nfds, zsock_fd_set *readfds,
51+
zsock_fd_set *writefds,
52+
zsock_fd_set *exceptfds,
53+
struct zsock_timeval *timeout);
5854

5955
/** Number of file descriptors which can be added to zsock_fd_set */
60-
#define ZSOCK_FD_SETSIZE ZVFS_FD_SETSIZE
56+
#define ZSOCK_FD_SETSIZE (sizeof(((zsock_fd_set *)0)->bitset) * 8)
6157

6258
/**
6359
* @brief Initialize (clear) fd_set
@@ -71,10 +67,7 @@ static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *wr
7167
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
7268
* @endrst
7369
*/
74-
static inline void ZSOCK_FD_ZERO(zsock_fd_set *set)
75-
{
76-
ZVFS_FD_ZERO(set);
77-
}
70+
void ZSOCK_FD_ZERO(zsock_fd_set *set);
7871

7972
/**
8073
* @brief Check whether socket is a member of fd_set
@@ -88,10 +81,7 @@ static inline void ZSOCK_FD_ZERO(zsock_fd_set *set)
8881
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
8982
* @endrst
9083
*/
91-
static inline int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
92-
{
93-
return ZVFS_FD_ISSET(fd, set);
94-
}
84+
int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set);
9585

9686
/**
9787
* @brief Remove socket from fd_set
@@ -105,10 +95,7 @@ static inline int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
10595
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
10696
* @endrst
10797
*/
108-
static inline void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
109-
{
110-
ZVFS_FD_CLR(fd, set);
111-
}
98+
void ZSOCK_FD_CLR(int fd, zsock_fd_set *set);
11299

113100
/**
114101
* @brief Add socket to fd_set
@@ -122,10 +109,7 @@ static inline void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
122109
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
123110
* @endrst
124111
*/
125-
static inline void ZSOCK_FD_SET(int fd, zsock_fd_set *set)
126-
{
127-
ZVFS_FD_SET(fd, set);
128-
}
112+
void ZSOCK_FD_SET(int fd, zsock_fd_set *set);
129113

130114
/** @cond INTERNAL_HIDDEN */
131115

@@ -169,6 +153,8 @@ static inline void FD_SET(int fd, zsock_fd_set *set)
169153
}
170154
#endif
171155

156+
#include <zephyr/syscalls/socket_select.h>
157+
172158
/**
173159
* @}
174160
*/

include/zephyr/posix/sys/select.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@
1313
extern "C" {
1414
#endif
1515

16-
#undef fd_set
1716
#define fd_set zsock_fd_set
18-
19-
#define FD_SETSIZE ZVFS_FD_SETSIZE
17+
#define FD_SETSIZE ZSOCK_FD_SETSIZE
18+
#define FD_ZERO ZSOCK_FD_ZERO
19+
#define FD_SET ZSOCK_FD_SET
20+
#define FD_CLR ZSOCK_FD_CLR
21+
#define FD_ISSET ZSOCK_FD_ISSET
2022

2123
struct timeval;
2224

23-
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
24-
void FD_CLR(int fd, fd_set *fdset);
25-
int FD_ISSET(int fd, fd_set *fdset);
26-
void FD_SET(int fd, fd_set *fdset);
27-
void FD_ZERO(fd_set *fdset);
25+
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
2826

2927
#ifdef __cplusplus
3028
}

include/zephyr/sys/fdtable.h

+1-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <stdarg.h>
1010
#include <sys/types.h>
11-
1211
/* FIXME: For native_posix ssize_t, off_t. */
1312
#include <zephyr/fs/fs.h>
1413
#include <zephyr/kernel.h>
@@ -208,23 +207,9 @@ struct zvfs_pollfd {
208207

209208
__syscall int zvfs_poll(struct zvfs_pollfd *fds, int nfds, int poll_timeout);
210209

211-
struct zvfs_fd_set {
210+
struct zsock_fd_set {
212211
uint32_t bitset[(CONFIG_ZVFS_OPEN_MAX + 31) / 32];
213212
};
214-
215-
#define ZVFS_FD_SETSIZE (sizeof(((struct zvfs_fd_set *)0)->bitset) * 8)
216-
217-
void ZVFS_FD_CLR(int fd, struct zvfs_fd_set *fdset);
218-
int ZVFS_FD_ISSET(int fd, struct zvfs_fd_set *fdset);
219-
void ZVFS_FD_SET(int fd, struct zvfs_fd_set *fdset);
220-
void ZVFS_FD_ZERO(struct zvfs_fd_set *fdset);
221-
222-
struct timespec;
223-
__syscall int zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
224-
struct zvfs_fd_set *ZRESTRICT writefds,
225-
struct zvfs_fd_set *ZRESTRICT errorfds,
226-
const struct timeval *ZRESTRICT timeout);
227-
228213
/**
229214
* Request codes for fd_op_vtable.ioctl().
230215
*
@@ -254,6 +239,4 @@ enum {
254239
}
255240
#endif
256241

257-
#include <zephyr/syscalls/fdtable.h>
258-
259242
#endif /* ZEPHYR_INCLUDE_SYS_FDTABLE_H_ */

lib/os/zvfs/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
zephyr_library()
44
zephyr_library_sources_ifdef(CONFIG_ZVFS_EVENTFD zvfs_eventfd.c)
55
zephyr_library_sources_ifdef(CONFIG_ZVFS_POLL zvfs_poll.c)
6-
zephyr_library_sources_ifdef(CONFIG_ZVFS_SELECT zvfs_select.c)

lib/os/zvfs/Kconfig

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ config ZVFS_POLL_MAX
4949
help
5050
Maximum number of entries supported for poll() call.
5151

52-
config ZVFS_SELECT
53-
bool "ZVFS select"
54-
help
55-
Enable support for zvfs_select().
56-
5752
endif # ZVFS_POLL
5853

5954
endif # ZVFS

lib/posix/options/Kconfig.device_io

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ config POSIX_DEVICE_IO
1010
select REQUIRES_FULL_LIBC
1111
select ZVFS
1212
select ZVFS_POLL
13-
select ZVFS_SELECT
1413
help
1514
Select 'y' here and Zephyr will provide an implementation of the POSIX_DEVICE_IO Option
1615
Group such as FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO(), close(), fdopen(), fileno(), open(),

lib/posix/options/device_io.c

+3-21
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,14 @@
1010
#include <zephyr/posix/poll.h>
1111
#include <zephyr/posix/unistd.h>
1212
#include <zephyr/posix/sys/select.h>
13+
#include <zephyr/posix/sys/socket.h>
1314

1415
/* prototypes for external, not-yet-public, functions in fdtable.c or fs.c */
1516
int zvfs_close(int fd);
1617
int zvfs_open(const char *name, int flags);
1718
ssize_t zvfs_read(int fd, void *buf, size_t sz, size_t *from_offset);
1819
ssize_t zvfs_write(int fd, const void *buf, size_t sz, size_t *from_offset);
1920

20-
void FD_CLR(int fd, struct zvfs_fd_set *fdset)
21-
{
22-
return ZVFS_FD_CLR(fd, (struct zvfs_fd_set *)fdset);
23-
}
24-
25-
int FD_ISSET(int fd, struct zvfs_fd_set *fdset)
26-
{
27-
return ZVFS_FD_ISSET(fd, (struct zvfs_fd_set *)fdset);
28-
}
29-
30-
void FD_SET(int fd, struct zvfs_fd_set *fdset)
31-
{
32-
ZVFS_FD_SET(fd, (struct zvfs_fd_set *)fdset);
33-
}
34-
35-
void FD_ZERO(fd_set *fdset)
36-
{
37-
ZVFS_FD_ZERO((struct zvfs_fd_set *)fdset);
38-
}
39-
4021
int close(int fd)
4122
{
4223
return zvfs_close(fd);
@@ -93,7 +74,8 @@ FUNC_ALIAS(read, _read, ssize_t);
9374

9475
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
9576
{
96-
return zvfs_select(nfds, readfds, writefds, exceptfds, timeout);
77+
/* TODO: create zvfs_select() and dispatch to subsystems based on file type */
78+
return zsock_select(nfds, readfds, writefds, exceptfds, (struct zsock_timeval *)timeout);
9779
}
9880

9981
ssize_t write(int fd, const void *buf, size_t sz)

subsys/net/lib/sockets/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
zephyr_syscall_header(
44
${ZEPHYR_BASE}/include/zephyr/net/socket.h
5+
${ZEPHYR_BASE}/include/zephyr/net/socket_select.h
56
)
67

78
zephyr_library_include_directories(.)
89

910
zephyr_library_sources(
1011
getaddrinfo.c
1112
sockets.c
13+
sockets_select.c
1214
)
1315

1416
if(NOT CONFIG_NET_SOCKETS_OFFLOAD)

subsys/net/lib/sockets/Kconfig

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ menuconfig NET_SOCKETS
77
bool "BSD Sockets compatible API"
88
select ZVFS
99
select ZVFS_POLL
10-
select ZVFS_SELECT
1110
help
1211
Provide BSD Sockets like API on top of native Zephyr networking API.
1312

0 commit comments

Comments
 (0)