X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fnetwork%2Fpoll.c;h=f6f9050effd9df1f7c1ffd4b4f2d0b293295d2de;hb=77a5fef919c5e2668991b9ae6e3e44a9901835e8;hp=b50cb835d83ee2a05d9c715a5cf94acaf10a0387;hpb=057e689f92d55d9b3e5889a18e749b62f1fe3924;p=vlc diff --git a/src/network/poll.c b/src/network/poll.c index b50cb835d8..f6f9050eff 100644 --- a/src/network/poll.c +++ b/src/network/poll.c @@ -21,20 +21,32 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#ifndef HAVE_POLL +#include +#include + +#ifdef HAVE_POLL +struct pollfd; + +int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout) +{ + (void)fds; (void)nfds; (void)timeout; + abort (); +} +#else /* !HAVE_POLL */ #include #include #include -int poll (struct pollfd *fds, unsigned nfds, int timeout) +int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout) { fd_set rdset, wrset, exset; struct timeval tv = { 0, 0 }; int val = -1; - FD_ZERO (&rdset); FD_ZERO (&wrset); FD_ZERO (&exset); @@ -44,8 +56,26 @@ int poll (struct pollfd *fds, unsigned nfds, int timeout) if (val < fd) val = fd; - /* I assume the OS has a solution select overflow if it does not have - * poll(). If it did not, we are screwed anyway. */ + /* 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. + * + * With BeOS, the situation is unknown (FIXME: document). + */ if (fds[i].events & POLLIN) FD_SET (fd, &rdset); if (fds[i].events & POLLOUT) @@ -61,7 +91,7 @@ int poll (struct pollfd *fds, unsigned nfds, int timeout) tv.tv_usec = d.rem * 1000; } - val = select (val + 1, &rdset, &wrset, NULL, + val = select (val + 1, &rdset, &wrset, &exset, (timeout >= 0) ? &tv : NULL); if (val == -1) return -1;