[vlc-devel] [PATCH 2/3] poll: only wait and call WSAEnumNetworkEvents() if select() reported nothing
Steve Lhomme
robux4 at videolabs.io
Wed Jul 13 18:50:21 CEST 2016
---
compat/poll.c | 93 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 51 insertions(+), 42 deletions(-)
diff --git a/compat/poll.c b/compat/poll.c
index 91c2d81..a6dadb9 100644
--- a/compat/poll.c
+++ b/compat/poll.c
@@ -209,54 +209,63 @@ int poll(struct pollfd *fds, unsigned nfds, int timeout)
ret = WSA_WAIT_EVENT_0 + i;
}
- if (ret == WSA_WAIT_FAILED)
+ if (ret == WSA_WAIT_FAILED && to > 0)
+ {
ret = WSAWaitForMultipleEvents(nfds, evts, FALSE, to, TRUE);
+ for (unsigned i = 0; i < nfds; i++)
+ {
+ WSANETWORKEVENTS ne;
+
+ if (WSAEnumNetworkEvents(fds[i].fd, evts[i], &ne))
+ memset(&ne, 0, sizeof (ne));
+ WSAEventSelect(fds[i].fd, evts[i], 0);
+
+ if (ne.lNetworkEvents & FD_CONNECT)
+ {
+ fds[i].revents |= POLLWRNORM;
+ if (ne.iErrorCode[FD_CONNECT_BIT] != 0)
+ fds[i].revents |= POLLERR;
+ }
+ if (ne.lNetworkEvents & FD_CLOSE)
+ {
+ fds[i].revents |= POLLRDNORM | POLLHUP;
+ if (ne.iErrorCode[FD_CLOSE_BIT] != 0)
+ fds[i].revents |= POLLERR;
+ }
+ if (ne.lNetworkEvents & FD_ACCEPT)
+ {
+ fds[i].revents |= POLLRDNORM;
+ if (ne.iErrorCode[FD_ACCEPT_BIT] != 0)
+ fds[i].revents |= POLLERR;
+ }
+ if (ne.lNetworkEvents & FD_OOB)
+ {
+ fds[i].revents |= POLLPRI;
+ if (ne.iErrorCode[FD_OOB_BIT] != 0)
+ fds[i].revents |= POLLERR;
+ }
+ if (ne.lNetworkEvents & FD_READ)
+ {
+ fds[i].revents |= POLLRDNORM;
+ if (ne.iErrorCode[FD_READ_BIT] != 0)
+ fds[i].revents |= POLLERR;
+ }
+ if (ne.lNetworkEvents & FD_WRITE)
+ {
+ fds[i].revents |= POLLWRNORM;
+ if (ne.iErrorCode[FD_WRITE_BIT] != 0)
+ fds[i].revents |= POLLERR;
+ }
+ }
+ }
+
unsigned count = 0;
for (unsigned i = 0; i < nfds; i++)
{
- WSANETWORKEVENTS ne;
-
- if (WSAEnumNetworkEvents(fds[i].fd, evts[i], &ne))
- memset(&ne, 0, sizeof (ne));
- WSAEventSelect(fds[i].fd, evts[i], 0);
+ /* only report the events requested, plus the special ones */
+ fds[i].revents &= fds[i].events | POLLERR | POLLHUP | POLLNVAL;
- if (ne.lNetworkEvents & FD_CONNECT)
- {
- fds[i].revents |= POLLWRNORM;
- if (ne.iErrorCode[FD_CONNECT_BIT] != 0)
- fds[i].revents |= POLLERR;
- }
- if (ne.lNetworkEvents & FD_CLOSE)
- {
- fds[i].revents |= (fds[i].events & POLLRDNORM) | POLLHUP;
- if (ne.iErrorCode[FD_CLOSE_BIT] != 0)
- fds[i].revents |= POLLERR;
- }
- if (ne.lNetworkEvents & FD_ACCEPT)
- {
- fds[i].revents |= POLLRDNORM;
- if (ne.iErrorCode[FD_ACCEPT_BIT] != 0)
- fds[i].revents |= POLLERR;
- }
- if (ne.lNetworkEvents & FD_OOB)
- {
- fds[i].revents |= POLLPRI;
- if (ne.iErrorCode[FD_OOB_BIT] != 0)
- fds[i].revents |= POLLERR;
- }
- if (ne.lNetworkEvents & FD_READ)
- {
- fds[i].revents |= POLLRDNORM;
- if (ne.iErrorCode[FD_READ_BIT] != 0)
- fds[i].revents |= POLLERR;
- }
- if (ne.lNetworkEvents & FD_WRITE)
- {
- fds[i].revents |= POLLWRNORM;
- if (ne.iErrorCode[FD_WRITE_BIT] != 0)
- fds[i].revents |= POLLERR;
- }
count += fds[i].revents != 0;
}
--
2.8.2
More information about the vlc-devel
mailing list