From 643f5782aa9abe98712de83f428694f3dc924b87 Mon Sep 17 00:00:00 2001 From: Simon Piriou Date: Sat, 22 Jul 2017 08:52:14 -0600 Subject: [PATCH] epoll: fix epoll_wait function --- fs/vfs/fs_epoll.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c index 6678ae10f2..69cd50170d 100644 --- a/fs/vfs/fs_epoll.c +++ b/fs/vfs/fs_epoll.c @@ -198,6 +198,7 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, */ FAR struct epoll_head *eph = (FAR struct epoll_head *)((intptr_t)epfd); + int counter; int rc; int i; @@ -219,13 +220,19 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, return rc; } - for (i = 0; i < rc; i++) + /* Iterate over non NULL event fds */ + + for (i = 0, counter = 0; i < rc && counter < eph->size; counter++) { - evs[i].data.fd = (pollevent_t)eph->evs[i].data.fd; - evs[i].events = (pollevent_t)eph->evs[i].revents; + if (eph->evs[counter].revents != 0) + { + evs[i].data.fd = eph->evs[counter].data.fd; + evs[i].events = eph->evs[counter].revents; + i += 1; + } } - return rc; + return i; } #endif /* CONFIG_DISABLE_POLL */