Skip to content

Commit

Permalink
Revert "net: sockets: move select() implementation to zvfs"
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
aescolar authored and Devansh0210 committed Jul 20, 2024
1 parent c87efa2 commit 985012f
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 146 deletions.
42 changes: 14 additions & 28 deletions include/zephyr/net/socket_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
* @{
*/

#include <time.h>

#include <zephyr/toolchain.h>
#include <zephyr/net/socket_types.h>
#include <zephyr/sys/fdtable.h>

#ifdef __cplusplus
extern "C" {
#endif

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

/**
* @brief Legacy function to poll multiple sockets for events
Expand All @@ -48,16 +47,13 @@ typedef struct zvfs_fd_set zsock_fd_set;
* it may conflict with generic POSIX ``select()`` function).
* @endrst
*/
static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *writefds,
zsock_fd_set *exceptfds, struct zsock_timeval *timeout)
{
struct timeval;

return zvfs_select(nfds, readfds, writefds, exceptfds, (struct timeval *)timeout);
}
__syscall int zsock_select(int nfds, zsock_fd_set *readfds,
zsock_fd_set *writefds,
zsock_fd_set *exceptfds,
struct zsock_timeval *timeout);

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

/**
* @brief Initialize (clear) fd_set
Expand All @@ -71,10 +67,7 @@ static inline int zsock_select(int nfds, zsock_fd_set *readfds, zsock_fd_set *wr
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
static inline void ZSOCK_FD_ZERO(zsock_fd_set *set)
{
ZVFS_FD_ZERO(set);
}
void ZSOCK_FD_ZERO(zsock_fd_set *set);

/**
* @brief Check whether socket is a member of fd_set
Expand All @@ -88,10 +81,7 @@ static inline void ZSOCK_FD_ZERO(zsock_fd_set *set)
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
static inline int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
{
return ZVFS_FD_ISSET(fd, set);
}
int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set);

/**
* @brief Remove socket from fd_set
Expand All @@ -105,10 +95,7 @@ static inline int ZSOCK_FD_ISSET(int fd, zsock_fd_set *set)
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
static inline void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
{
ZVFS_FD_CLR(fd, set);
}
void ZSOCK_FD_CLR(int fd, zsock_fd_set *set);

/**
* @brief Add socket to fd_set
Expand All @@ -122,10 +109,7 @@ static inline void ZSOCK_FD_CLR(int fd, zsock_fd_set *set)
* if :kconfig:option:`CONFIG_POSIX_API` is defined.
* @endrst
*/
static inline void ZSOCK_FD_SET(int fd, zsock_fd_set *set)
{
ZVFS_FD_SET(fd, set);
}
void ZSOCK_FD_SET(int fd, zsock_fd_set *set);

/** @cond INTERNAL_HIDDEN */

Expand Down Expand Up @@ -169,6 +153,8 @@ static inline void FD_SET(int fd, zsock_fd_set *set)
}
#endif

#include <zephyr/syscalls/socket_select.h>

/**
* @}
*/
Expand Down
14 changes: 6 additions & 8 deletions include/zephyr/posix/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
extern "C" {
#endif

#undef fd_set
#define fd_set zsock_fd_set

#define FD_SETSIZE ZVFS_FD_SETSIZE
#define FD_SETSIZE ZSOCK_FD_SETSIZE
#define FD_ZERO ZSOCK_FD_ZERO
#define FD_SET ZSOCK_FD_SET
#define FD_CLR ZSOCK_FD_CLR
#define FD_ISSET ZSOCK_FD_ISSET

struct timeval;

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout);
void FD_CLR(int fd, fd_set *fdset);
int FD_ISSET(int fd, fd_set *fdset);
void FD_SET(int fd, fd_set *fdset);
void FD_ZERO(fd_set *fdset);
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

#ifdef __cplusplus
}
Expand Down
19 changes: 1 addition & 18 deletions include/zephyr/sys/fdtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <stdarg.h>
#include <sys/types.h>

/* FIXME: For native_posix ssize_t, off_t. */
#include <zephyr/fs/fs.h>
#include <zephyr/kernel.h>
Expand Down Expand Up @@ -208,23 +207,9 @@ struct zvfs_pollfd {

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

struct zvfs_fd_set {
struct zsock_fd_set {
uint32_t bitset[(CONFIG_ZVFS_OPEN_MAX + 31) / 32];
};

#define ZVFS_FD_SETSIZE (sizeof(((struct zvfs_fd_set *)0)->bitset) * 8)

void ZVFS_FD_CLR(int fd, struct zvfs_fd_set *fdset);
int ZVFS_FD_ISSET(int fd, struct zvfs_fd_set *fdset);
void ZVFS_FD_SET(int fd, struct zvfs_fd_set *fdset);
void ZVFS_FD_ZERO(struct zvfs_fd_set *fdset);

struct timespec;
__syscall int zvfs_select(int nfds, struct zvfs_fd_set *ZRESTRICT readfds,
struct zvfs_fd_set *ZRESTRICT writefds,
struct zvfs_fd_set *ZRESTRICT errorfds,
const struct timeval *ZRESTRICT timeout);

/**
* Request codes for fd_op_vtable.ioctl().
*
Expand Down Expand Up @@ -254,6 +239,4 @@ enum {
}
#endif

#include <zephyr/syscalls/fdtable.h>

#endif /* ZEPHYR_INCLUDE_SYS_FDTABLE_H_ */
1 change: 0 additions & 1 deletion lib/os/zvfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
zephyr_library()
zephyr_library_sources_ifdef(CONFIG_ZVFS_EVENTFD zvfs_eventfd.c)
zephyr_library_sources_ifdef(CONFIG_ZVFS_POLL zvfs_poll.c)
zephyr_library_sources_ifdef(CONFIG_ZVFS_SELECT zvfs_select.c)
5 changes: 0 additions & 5 deletions lib/os/zvfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ config ZVFS_POLL_MAX
help
Maximum number of entries supported for poll() call.

config ZVFS_SELECT
bool "ZVFS select"
help
Enable support for zvfs_select().

endif # ZVFS_POLL

endif # ZVFS
1 change: 0 additions & 1 deletion lib/posix/options/Kconfig.device_io
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ config POSIX_DEVICE_IO
select REQUIRES_FULL_LIBC
select ZVFS
select ZVFS_POLL
select ZVFS_SELECT
help
Select 'y' here and Zephyr will provide an implementation of the POSIX_DEVICE_IO Option
Group such as FD_CLR(), FD_ISSET(), FD_SET(), FD_ZERO(), close(), fdopen(), fileno(), open(),
Expand Down
24 changes: 3 additions & 21 deletions lib/posix/options/device_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,14 @@
#include <zephyr/posix/poll.h>
#include <zephyr/posix/unistd.h>
#include <zephyr/posix/sys/select.h>
#include <zephyr/posix/sys/socket.h>

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

void FD_CLR(int fd, struct zvfs_fd_set *fdset)
{
return ZVFS_FD_CLR(fd, (struct zvfs_fd_set *)fdset);
}

int FD_ISSET(int fd, struct zvfs_fd_set *fdset)
{
return ZVFS_FD_ISSET(fd, (struct zvfs_fd_set *)fdset);
}

void FD_SET(int fd, struct zvfs_fd_set *fdset)
{
ZVFS_FD_SET(fd, (struct zvfs_fd_set *)fdset);
}

void FD_ZERO(fd_set *fdset)
{
ZVFS_FD_ZERO((struct zvfs_fd_set *)fdset);
}

int close(int fd)
{
return zvfs_close(fd);
Expand Down Expand Up @@ -93,7 +74,8 @@ FUNC_ALIAS(read, _read, ssize_t);

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
return zvfs_select(nfds, readfds, writefds, exceptfds, timeout);
/* TODO: create zvfs_select() and dispatch to subsystems based on file type */
return zsock_select(nfds, readfds, writefds, exceptfds, (struct zsock_timeval *)timeout);
}

ssize_t write(int fd, const void *buf, size_t sz)
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/lib/sockets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

zephyr_syscall_header(
${ZEPHYR_BASE}/include/zephyr/net/socket.h
${ZEPHYR_BASE}/include/zephyr/net/socket_select.h
)

zephyr_library_include_directories(.)

zephyr_library_sources(
getaddrinfo.c
sockets.c
sockets_select.c
)

if(NOT CONFIG_NET_SOCKETS_OFFLOAD)
Expand Down
1 change: 0 additions & 1 deletion subsys/net/lib/sockets/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ menuconfig NET_SOCKETS
bool "BSD Sockets compatible API"
select ZVFS
select ZVFS_POLL
select ZVFS_SELECT
help
Provide BSD Sockets like API on top of native Zephyr networking API.

Expand Down
Loading

0 comments on commit 985012f

Please sign in to comment.