From 3bbff549702a3d4cdc376459a57369b3408ff77a Mon Sep 17 00:00:00 2001 From: asmodai Date: Tue, 9 Apr 2002 05:41:00 +0000 Subject: Return correct number of total bits set in all fd_set's. Change case of POLLNVAL as an error. Remove POLLHUP and POLLERR from one case, their place is most likely amongst read events. PR: 33723 Submitted by: Alexander Litvin Reviewed by: deischen [Provided a small change to the PR patch as well] MFC after: 4 weeks --- lib/libpthread/thread/thr_select.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'lib/libpthread/thread') diff --git a/lib/libpthread/thread/thr_select.c b/lib/libpthread/thread/thr_select.c index 5860efe..8d03bbd 100644 --- a/lib/libpthread/thread/thr_select.c +++ b/lib/libpthread/thread/thr_select.c @@ -52,7 +52,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct pthread *curthread = _get_curthread(); struct timespec ts; int i, ret = 0, f_wait = 1; - int pfd_index, got_one = 0, fd_count = 0; + int pfd_index, got_events = 0, fd_count = 0; struct pthread_poll_data data; if (numfds > _thread_dtablesize) { @@ -166,12 +166,22 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, * this file descriptor from the fdset if * the requested event wasn't ready. */ - got_one = 0; + + /* + * First check for invalid descriptor. + * If found, set errno and return -1. + */ + if (data.fds[i].revents & POLLNVAL) { + errno = EBADF; + return -1; + } + + got_events = 0; if (readfds != NULL) { if (FD_ISSET(data.fds[i].fd, readfds)) { if (data.fds[i].revents & (POLLIN | POLLRDNORM)) - got_one = 1; + got_events++; else FD_CLR(data.fds[i].fd, readfds); } @@ -180,7 +190,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, if (FD_ISSET(data.fds[i].fd, writefds)) { if (data.fds[i].revents & (POLLOUT | POLLWRNORM | POLLWRBAND)) - got_one = 1; + got_events++; else FD_CLR(data.fds[i].fd, writefds); @@ -189,16 +199,15 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, if (exceptfds != NULL) { if (FD_ISSET(data.fds[i].fd, exceptfds)) { if (data.fds[i].revents & (POLLRDBAND | - POLLPRI | POLLHUP | POLLERR | - POLLNVAL)) - got_one = 1; + POLLPRI)) + got_events++; else FD_CLR(data.fds[i].fd, exceptfds); } } - if (got_one) - numfds++; + if (got_events != 0) + numfds+=got_events; } ret = numfds; } -- cgit v1.1