]> git.sesse.net Git - vlc/blobdiff - src/network/poll.c
Maemo: work-around segmentation fault when poll() unwinds
[vlc] / src / network / poll.c
index 7aa314db393c2aa618a5692899fc2240a783cd4e..eb97c83db07749449b3dfac987ff927a6bf089fe 100644 (file)
 # include "config.h"
 #endif
 
-#ifdef HAVE_POLL
+#include <vlc_common.h>
 #include <stdlib.h>
+#include <vlc_network.h>
+
+
+#if HAVE_MAEMO
+# include <signal.h>
+# include <errno.h>
+# include <poll.h>
+
+int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
+{
+    struct timespec tsbuf, *ts;
+    sigset_t set;
+    int canc, ret;
+
+    if (timeout != -1)
+    {
+        div_t d = div (timeout, 1000);
+        tsbuf.tv_sec = d.quot;
+        tsbuf.tv_nsec = d.rem * 1000000;
+        ts = &tsbuf;
+    }
+    else
+        ts = NULL;
+
+    pthread_sigmask (SIG_BLOCK, NULL, &set);
+    sigdelset (&set, SIGRTMIN);
+
+    canc = vlc_savecancel ();
+    ret = ppoll (fds, nfds, ts, &set);
+    vlc_restorecancel (canc);
+
+    vlc_testcancel ();
+    return ret;
+}
 
+#elif defined (HAVE_POLL)
 struct pollfd;
 
 int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
@@ -37,10 +72,7 @@ int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
 }
 #else /* !HAVE_POLL */
 
-#include <vlc_common.h>
 #include <string.h>
-#include <stdlib.h>
-#include <vlc_network.h>
 
 int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
 {