poll needs to set POLLNVAL if file descriptor is bad

This commit is contained in:
Gregory Nutt
2013-05-23 07:48:32 -06:00
parent 9d280a58aa
commit b5dd706120
2 changed files with 33 additions and 18 deletions
+2
View File
@@ -4777,3 +4777,5 @@
* net/net_poll.c: When readahead data is availalbe, the network poll * net/net_poll.c: When readahead data is availalbe, the network poll
logic should set POLLIN (or POLLRDNORM), not POLLOUT. Max Holtzberg logic should set POLLIN (or POLLRDNORM), not POLLOUT. Max Holtzberg
(2013-5-23) (2013-5-23)
* fs/fs_poll.c: Actually, it should not ignore invlid descriptors, it
should set the POLLNVAL event and return immediately (2013-5-23).
+20 -7
View File
@@ -162,18 +162,31 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem)
/* Process each descriptor in the list */ /* Process each descriptor in the list */
for (i = 0; i < nfds; i++) for (i = 0; i < nfds; i++)
{
/* Ignore negative descriptors */
if (fds[i].fd >= 0)
{ {
/* Setup the poll descriptor */ /* Setup the poll descriptor */
fds[i].sem = sem; fds[i].sem = sem;
fds[i].revents = 0;
fds[i].priv = NULL; fds[i].priv = NULL;
/* Set up the poll */ /* Check for invalid descriptors */
if (fds[i].fd < 0)
{
/* Set POLLNVAL to indicate the invalid fd member */
fds[i].revents = POLLNVAL;
/* And increment the semaphore so that poll will return
* immediately (but with a successful return value).
*/
sem_post(sem);
}
else
{
/* Set up the poll on this valid file descriptor */
fds[i].revents = 0;
ret = poll_fdsetup(fds[i].fd, &fds[i], true); ret = poll_fdsetup(fds[i].fd, &fds[i], true);
if (ret < 0) if (ret < 0)
@@ -219,6 +232,7 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count)
{ {
ret = status; ret = status;
} }
}
/* Check if any events were posted */ /* Check if any events were posted */
@@ -231,7 +245,6 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count)
fds[i].sem = NULL; fds[i].sem = NULL;
} }
}
return ret; return ret;
} }