]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
sockets.c: Make select() not return errors when using it with file descriptor types...
authorCostin Lupu <costin.lupu@cs.pub.ro>
Sat, 16 Nov 2019 21:50:52 +0000 (23:50 +0200)
committerCostin Lupu <costin.lup@gmail.com>
Sun, 17 Nov 2019 10:43:08 +0000 (12:43 +0200)
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 <costin.lupu@cs.pub.ro>
Reviewed-by: Stefan Teodorescu <stefanl.teodorescu@gmail.com>
Config.uk
sockets.c

index 92df4d308033bf5049314255385121d4e2459199..8f501fc5ed39f3e282817a912313ea2fb79e5cf9 100644 (file)
--- 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
index cd84b97c215dee50ec898937f69d4dcec7e1891d..c2cf57ffe509bfddcd04d706254164983fc1ffb6 100644 (file)
--- 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;