From aee924ba854034f8b085a429802e043b9f0de446 Mon Sep 17 00:00:00 2001 From: Costin Lupu Date: Sat, 16 Nov 2019 23:50:52 +0200 Subject: [PATCH] sockets.c: Make select() not return errors when using it with file descriptor types other than sockets lwip's select() implementation supports only sockets. Up until now, we returned errors when using select() with other file descriptor types. These changes make it possible to use other file descriptor types as well, even though they will be ignored. Signed-off-by: Costin Lupu Reviewed-by: Stefan Teodorescu --- Config.uk | 10 ++++++++++ sockets.c | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Config.uk b/Config.uk index 92df4d3..8f501fc 100644 --- a/Config.uk +++ b/Config.uk @@ -162,6 +162,16 @@ config LWIP_SOCKET depends on LWIP_THREADS && (LWIP_UDP || LWIP_TCP) default y +if LWIP_SOCKET + config LWIP_SOCKET_SELECT_GENERIC_FDS + bool "Use select() with any file descriptor type" + default y + help + lwip's select() implementation supports only sockets. This + configuration option makes it possible to use other file descriptor + types as well, even though they are not supported by lwip. +endif + menuconfig LWIP_DEBUG bool "Debug messages" default n diff --git a/sockets.c b/sockets.c index cd84b97..c2cf57f 100644 --- a/sockets.c +++ b/sockets.c @@ -497,12 +497,20 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, if (readfds && FD_ISSET(i, readfds)) { file = sock_net_file_get(i); if (PTRISERR(file)) { +#if CONFIG_LWIP_SOCKET_SELECT_GENERIC_FDS + /* We allow other fd types, but we don't support them */ + if (PTR2ERR(file) == -EBADF) { + FD_CLR(i, readfds); + continue; + } +#else LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket descriptor\n")); ret = -1; /* Setting the errno */ SOCK_NET_SET_ERRNO(PTR2ERR(file)); goto EXIT; +#endif } if (maxfd < file->sock_fd) maxfd = file->sock_fd; @@ -512,12 +520,20 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, if (writefds && FD_ISSET(i, writefds)) { file = sock_net_file_get(i); if (PTRISERR(file)) { +#if CONFIG_LWIP_SOCKET_SELECT_GENERIC_FDS + /* We allow other fd types, but we don't support them */ + if (PTR2ERR(file) == -EBADF) { + FD_CLR(i, writefds); + continue; + } +#else LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket descriptor\n")); ret = -1; /* Setting the errno */ SOCK_NET_SET_ERRNO(PTR2ERR(file)); goto EXIT; +#endif } if (maxfd < file->sock_fd) maxfd = file->sock_fd; @@ -527,12 +543,20 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, if (exceptfds && FD_ISSET(i, exceptfds)) { file = sock_net_file_get(i); if (PTRISERR(file)) { +#if CONFIG_LWIP_SOCKET_SELECT_GENERIC_FDS + /* We allow other fd types, but we don't support them */ + if (PTR2ERR(file) == -EBADF) { + FD_CLR(i, exceptfds); + continue; + } +#else LWIP_DEBUGF(SOCKETS_DEBUG, ("failed to identify socket descriptor\n")); ret = -1; /* Setting the errno */ SOCK_NET_SET_ERRNO(PTR2ERR(file)); goto EXIT; +#endif } if (maxfd < file->sock_fd) maxfd = file->sock_fd; -- 2.39.5