[vlc-commits] Implement vlc_poll() on OS/2
KO Myung-Hun
git at videolan.org
Thu Nov 10 21:38:25 CET 2011
vlc | branch: master | KO Myung-Hun <komh at chollian.net> | Sun Nov 6 18:58:28 2011 +0900| [feeb0ed824c9740b9262bc7a401dc7898f9d361c] | committer: Rémi Denis-Courmont
Implement vlc_poll() on OS/2
Modified-and...
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=feeb0ed824c9740b9262bc7a401dc7898f9d361c
---
configure.ac | 2 +-
src/Makefile.am | 1 +
src/os2/poll.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/win32/poll.c | 6 ---
4 files changed, 111 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9d554a2..48efc69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -566,7 +566,7 @@ dnl Check for poll
AC_SEARCH_LIBS(poll, [poll], [
AC_DEFINE(HAVE_POLL, 1, [Define to 1 if the OS has poll().])
], [
- AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce"], [
+ AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "mingwce" -a "${SYS}" != "os2"], [
AC_MSG_ERROR([poll() is required.])
])
])
diff --git a/src/Makefile.am b/src/Makefile.am
index a64f891..e93961d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -281,6 +281,7 @@ SOURCES_libvlc_os2 = \
misc/atomic.c \
posix/filesystem.c \
posix/plugin.c \
+ os2/poll.c \
os2/thread.c \
os2/specific.c \
$(NULL)
diff --git a/src/os2/poll.c b/src/os2/poll.c
new file mode 100644
index 0000000..a4ef100
--- /dev/null
+++ b/src/os2/poll.c
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * poll.c: poll() emulation for OS/2
+ *****************************************************************************
+ * Copyright © 2011 KO Myung-Hun <komh at chollian.et>
+ * Copyright © 2007 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/time.h>
+
+#include <vlc_common.h>
+#include <vlc_network.h>
+
+int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
+{
+ fd_set rdset;
+ fd_set wrset;
+ fd_set exset;
+ struct timeval tv = { 0, 0 };
+ int val;
+
+resume:
+ val = -1;
+ vlc_testcancel ();
+
+ FD_ZERO (&rdset);
+ FD_ZERO (&wrset);
+ FD_ZERO (&exset);
+ for (unsigned i = 0; i < nfds; i++)
+ {
+ int fd = fds[i].fd;
+
+ if (fds[i].fd >= FD_SETSIZE)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (val < fd)
+ val = fd;
+
+ if (fds[i].events & POLLIN)
+ FD_SET (fd, &rdset);
+ if (fds[i].events & POLLOUT)
+ FD_SET (fd, &wrset);
+ if (fds[i].events & POLLPRI)
+ FD_SET (fd, &exset);
+ }
+
+#ifndef HAVE_ALERTABLE_SELECT
+# warning FIXME! Fix cancellation and remove this crap.
+ if ((timeout < 0) || (timeout > 50))
+ {
+ tv.tv_sec = 0;
+ tv.tv_usec = 50000;
+ }
+ else
+#endif
+ if (timeout >= 0)
+ {
+ div_t d = div (timeout, 1000);
+ tv.tv_sec = d.quot;
+ tv.tv_usec = d.rem * 1000;
+ }
+
+ val = select (val + 1, &rdset, &wrset, &exset, &tv);
+
+#ifndef HAVE_ALERTABLE_SELECT
+ if (val == 0)
+ {
+ if (timeout > 0)
+ timeout -= (timeout > 50) ? 50 : timeout;
+ if (timeout != 0)
+ goto resume;
+ }
+#endif
+
+ if (val == -1)
+ return -1;
+
+ 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);
+ }
+ return val;
+}
diff --git a/src/win32/poll.c b/src/win32/poll.c
index 4fa693f..1b2ec48 100644
--- a/src/win32/poll.c
+++ b/src/win32/poll.c
@@ -35,12 +35,6 @@
#define FD_SETSIZE 0
#include <vlc_network.h>
-#ifdef __OS2__
-#include <sys/time.h>
-#include <sys/select.h>
-#define SOCKET unsigned
-#endif
-
int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
{
size_t setsize = sizeof (fd_set) + nfds * sizeof (SOCKET);
More information about the vlc-commits
mailing list