Return 0 for a timed-out select()
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 4 Apr 2016 21:02:53 +0000 (17:02 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 5 Apr 2016 19:42:19 +0000 (15:42 -0400)
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/iplib/select.c

index 18176e6..7fc22b5 100644 (file)
@@ -153,6 +153,7 @@ int select(int nfds, fd_set *readfds, fd_set *writefds,
        struct epoll_event ep_ev;
        struct epoll_event *ep_results;
        uintptr_t my_call_id;
+       int ret;
        int ep_timeout = select_tv_to_ep_timeout(timeout);
 
        run_once(select_init());
@@ -236,10 +237,12 @@ int select(int nfds, fd_set *readfds, fd_set *writefds,
        }
        /* Don't care which ones were set; we'll just tell the user they all were
         * set.  If they can't handle that, this whole plan won't work. */
-       epoll_wait(epoll_fd, ep_results, FD_SETSIZE, ep_timeout);
+       ret = epoll_wait(epoll_fd, ep_results, FD_SETSIZE, ep_timeout);
        uth_mutex_unlock(sleep_mtx);
        free(ep_results);
        /* TODO: consider updating timeval.  It's not mandatory (POSIX). */
+       if (ret == 0)   /* timeout */
+               return 0;
        return nfds;
 }