[vlc-commits] poll: deal with invalid file descriptors more like specified
Rémi Denis-Courmont
git at videolan.org
Wed Aug 20 01:53:43 CEST 2014
vlc/vlc-2.2 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Aug 17 16:28:36 2014 +0300| [2d919681437a23d2595ebe87b18ba634b1832e79] | committer: Jean-Baptiste Kempf
poll: deal with invalid file descriptors more like specified
(cherry picked from commit 5ac516c9c7a2acfdc5b8f9d94eb3833efa7f26cc)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=2d919681437a23d2595ebe87b18ba634b1832e79
---
compat/poll.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/compat/poll.c b/compat/poll.c
index 8c37609..21e6d59 100644
--- a/compat/poll.c
+++ b/compat/poll.c
@@ -114,7 +114,32 @@ int (poll) (struct pollfd *fds, unsigned nfds, int timeout)
val = select (val + 1, rdset, wrset, exset,
(timeout >= 0) ? &tv : NULL);
if (val == -1)
- return -1;
+ {
+#ifndef _WIN32
+ if (errno != EBADF)
+#else
+ if (WSAGetLastError () != WSAENOTSOCK)
+#endif
+ return -1;
+
+ val = 0;
+
+ for (unsigned i = 0; i < nfds; i++)
+#ifndef _WIN32
+ if (fcntl (fds[i].fd, F_GETFD) == -1)
+#else
+ if (getsockopt (fds[i].fd, SOL_SOCKET, SO_REUSEADDR,
+ &(DWORD){ 0 }, &(int){ sizeof (DWORD) }) != 0)
+#endif
+ {
+ fds[i].revents = POLLNVAL;
+ val++;
+ }
+ else
+ fds[i].revents = 0;
+
+ return val ? val : -1;
+ }
for (unsigned i = 0; i < nfds; i++)
{
More information about the vlc-commits
mailing list