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
This commit is contained in:
Jeroen Ruigrok van der Werven 2002-04-09 05:41:00 +00:00
parent 1c47b73286
commit 92d2baa6a2
3 changed files with 54 additions and 27 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}