summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authorasmodai <asmodai@FreeBSD.org>2002-04-09 05:41:00 +0000
committerasmodai <asmodai@FreeBSD.org>2002-04-09 05:41:00 +0000
commit3bbff549702a3d4cdc376459a57369b3408ff77a (patch)
treedd6e518453f668a1d3b6c8e9aa7cae0f824394f6 /lib/libpthread
parent550927f578ef2d8d67cddee9cd1671b31132477b (diff)
downloadFreeBSD-src-3bbff549702a3d4cdc376459a57369b3408ff77a.zip
FreeBSD-src-3bbff549702a3d4cdc376459a57369b3408ff77a.tar.gz
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 <archer@whichever.org> Reviewed by: deischen [Provided a small change to the PR patch as well] MFC after: 4 weeks
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/thread/thr_select.c27
1 files changed, 18 insertions, 9 deletions
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;
}
OpenPOWER on IntegriCloud