]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Fix poll() ret variable type and select() maxfd calculation
authorMihai Pogonaru <pogonarumihai@gmail.com>
Wed, 26 Jun 2019 01:54:32 +0000 (04:54 +0300)
committerFelipe Huici <felipe.huici@neclab.eu>
Wed, 26 Jun 2019 09:05:40 +0000 (11:05 +0200)
Poll ret variable must be declared as int
Select must calculate maxfd as the maximum between lwip file descriptors

Signed-off-by: Mihai Pogonaru <pogonarumihai@gmail.com>
Reviewed-by: Costin Lupu <costin.lupu@cs.pub.ro>
sockets.c

index 77235e9d010a7e12d00a326a9662f57f2c85a905..e95758d83e8b55c38bbfc080d52272431cb3525b 100644 (file)
--- a/sockets.c
+++ b/sockets.c
@@ -335,7 +335,8 @@ EXIT:
 
 int poll(struct pollfd fds[], nfds_t nfds, int timeout)
 {
-       unsigned int i, ret;
+       int ret;
+       unsigned int i;
        struct sock_net_file *file;
        struct pollfd lwip_fds[nfds];
 
@@ -395,7 +396,6 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
        maxfd = 0;
        for (i = 0; i < nfds; i++) {
                if (readfds && FD_ISSET(i, readfds)) {
-                       maxfd = i;
                        file = sock_net_file_get(i);
                        if (PTRISERR(file)) {
                                LWIP_DEBUGF(SOCKETS_DEBUG,
@@ -405,11 +405,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
                                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                                goto EXIT;
                        }
+                       if (maxfd < file->sock_fd)
+                               maxfd = file->sock_fd;
                        FD_SET(file->sock_fd, &rd);
                        vfscore_put_file(&file->vfscore_file); /* release refcount */
                }
                if (writefds && FD_ISSET(i, writefds)) {
-                       maxfd = i;
                        file = sock_net_file_get(i);
                        if (PTRISERR(file)) {
                                LWIP_DEBUGF(SOCKETS_DEBUG,
@@ -419,11 +420,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
                                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                                goto EXIT;
                        }
+                       if (maxfd < file->sock_fd)
+                               maxfd = file->sock_fd;
                        FD_SET(file->sock_fd, &wr);
                        vfscore_put_file(&file->vfscore_file); /* release refcount */
                }
                if (exceptfds && FD_ISSET(i, exceptfds)) {
-                       maxfd = i;
                        file = sock_net_file_get(i);
                        if (PTRISERR(file)) {
                                LWIP_DEBUGF(SOCKETS_DEBUG,
@@ -433,6 +435,8 @@ int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
                                SOCK_NET_SET_ERRNO(PTR2ERR(file));
                                goto EXIT;
                        }
+                       if (maxfd < file->sock_fd)
+                               maxfd = file->sock_fd;
                        FD_SET(file->sock_fd, &xc);
                        vfscore_put_file(&file->vfscore_file); /* release refcount */
                }