Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
1a0ad6c1
Commit
1a0ad6c1
authored
Nov 24, 2010
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Win32: fix poll() with more than 64 sockets
parent
899a6313
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
27 deletions
+46
-27
src/network/poll.c
src/network/poll.c
+46
-27
No files found.
src/network/poll.c
View file @
1a0ad6c1
...
...
@@ -70,23 +70,37 @@ int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
(
void
)
fds
;
(
void
)
nfds
;
(
void
)
timeout
;
abort
();
}
#else
/* !HAVE_POLL */
#elif defined (WIN32)
#include <string.h>
#include <errno.h>
int
vlc_poll
(
struct
pollfd
*
fds
,
unsigned
nfds
,
int
timeout
)
{
fd_set
rdset
,
wrset
,
exset
;
size_t
setsize
=
sizeof
(
fd_set
)
+
(
nfds
-
FD_SETSIZE
)
*
sizeof
(
SOCKET
);
fd_set
*
rdset
=
malloc
(
setsize
);
fd_set
*
wrset
=
malloc
(
setsize
);
fd_set
*
exset
=
malloc
(
setsize
);
struct
timeval
tv
=
{
0
,
0
};
int
val
;
if
(
unlikely
(
rdset
==
NULL
||
wrset
==
NULL
||
exset
==
NULL
))
{
free
(
rdset
);
free
(
wrset
);
free
(
exset
);
errno
=
ENOMEM
;
return
-
1
;
}
resume:
val
=
-
1
;
vlc_testcancel
();
FD_ZERO
(
&
rdset
);
FD_ZERO
(
&
wrset
);
FD_ZERO
(
&
exset
);
FD_ZERO
(
rdset
);
FD_ZERO
(
wrset
);
FD_ZERO
(
exset
);
for
(
unsigned
i
=
0
;
i
<
nfds
;
i
++
)
{
int
fd
=
fds
[
i
].
fd
;
...
...
@@ -94,23 +108,22 @@ resume:
val
=
fd
;
/* With POSIX, FD_SET & FD_ISSET are not defined if fd is negative or
* bigger or equal than FD_SETSIZE. That is one of the reasons why VLC
* uses poll() rather than select(). Most POSIX systems implement
* fd_set has a bit field with no sanity checks. This is especially bad
* on systems (such as BSD) that have no process open files limit by
* default, such that it is quite feasible to get fd >= FD_SETSIZE.
* The next instructions will result in a buffer overflow if run on
* a POSIX system, and the later FD_ISSET will do undefined memory
* access.
*
* With Winsock, fd_set is a table of integers. This is awfully slow.
* However, FD_SET and FD_ISSET silently and safely discard
* overflows. If it happens we will loose socket events. Note that
* most (if not all) Winsock SOCKET handles are actually bigger than
* FD_SETSIZE in terms of absolute value - they are not POSIX file
* descriptors. From Vista, there is a much nicer WSAPoll(), but Mingw
* is yet to support it.
*/
* bigger or equal than FD_SETSIZE. That is one of the reasons why VLC
* uses poll() rather than select(). Most POSIX systems implement
* fd_set has a bit field with no sanity checks. This is especially bad
* on systems (such as BSD) that have no process open files limit by
* default, such that it is quite feasible to get fd >= FD_SETSIZE.
* The next instructions will result in a buffer overflow if run on
* a POSIX system, and the later FD_ISSET would perform an undefined
* memory read.
*
* With Winsock, fd_set is a table of integers. This is awfully slow.
* However, FD_SET and FD_ISSET silently and safely discard excess
* entries. Here, overflow cannot happen anyway: fd_set of adequate
* size are allocated.
* Note that Vista has a much nicer WSAPoll(), but Mingw does not
* support it yet.
*/
if
(
fds
[
i
].
events
&
POLLIN
)
FD_SET
((
SOCKET
)
fd
,
rdset
);
if
(
fds
[
i
].
events
&
POLLOUT
)
...
...
@@ -135,7 +148,7 @@ resume:
tv
.
tv_usec
=
d
.
rem
*
1000
;
}
val
=
select
(
val
+
1
,
&
rdset
,
&
wrset
,
&
exset
,
val
=
select
(
val
+
1
,
rdset
,
wrset
,
exset
,
/*(timeout >= 0) ?*/
&
tv
/*: NULL*/
);
#ifndef HAVE_ALERTABLE_SELECT
...
...
@@ -154,10 +167,16 @@ resume:
for
(
unsigned
i
=
0
;
i
<
nfds
;
i
++
)
{
int
fd
=
fds
[
i
].
fd
;
fds
[
i
].
revents
=
(
FD_ISSET
(
fd
,
&
rdset
)
?
POLLIN
:
0
)
|
(
FD_ISSET
(
fd
,
&
wrset
)
?
POLLOUT
:
0
)
|
(
FD_ISSET
(
fd
,
&
exset
)
?
POLLPRI
:
0
);
fds
[
i
].
revents
=
(
FD_ISSET
(
fd
,
rdset
)
?
POLLIN
:
0
)
|
(
FD_ISSET
(
fd
,
wrset
)
?
POLLOUT
:
0
)
|
(
FD_ISSET
(
fd
,
exset
)
?
POLLPRI
:
0
);
}
free
(
exset
);
free
(
wrset
);
free
(
rdset
);
return
val
;
}
#endif
/* !HAVE_POLL */
#else
# error poll() not implemented!
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment