[vlc-commits] access: add vlc_access_poll()

Rémi Denis-Courmont git at videolan.org
Wed Feb 18 18:44:47 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb 18 19:05:01 2015 +0200| [bab9bfbf9053e1ce1c5d53ea62fb92b143f6739a] | committer: Rémi Denis-Courmont

access: add vlc_access_poll()

This is an attempt to complement (and possibly eventually replace) the
net_Read() & net_Write() family of functions. In some cases, it is
desirable to handel I/O events on more than one file descriptors.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bab9bfbf9053e1ce1c5d53ea62fb92b143f6739a
---

 include/vlc_access.h |    4 ++++
 src/input/access.c   |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym   |    1 +
 3 files changed, 56 insertions(+)

diff --git a/include/vlc_access.h b/include/vlc_access.h
index e83d53f..ddb5948 100644
--- a/include/vlc_access.h
+++ b/include/vlc_access.h
@@ -151,6 +151,10 @@ static inline void access_InitFields( access_t *p_a )
  */
 VLC_API input_thread_t * access_GetParentInput( access_t *p_access ) VLC_USED;
 
+struct pollfd;
+
+VLC_API int vlc_access_poll(access_t *, struct pollfd *, unsigned long, int);
+
 #define ACCESS_SET_CALLBACKS( read, block, control, seek ) \
     do { \
         p_access->pf_read = (read); \
diff --git a/src/input/access.c b/src/input/access.c
index a9b2804..184074c 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -25,6 +25,13 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
+#include <stdlib.h>
+#include <errno.h>
+#ifdef HAVE_POLL
+# include <poll.h>
+#endif
+
 #include "access.h"
 #include <libvlc.h>
 #include <vlc_url.h>
@@ -124,3 +131,47 @@ input_thread_t * access_GetParentInput( access_t *p_access )
     return p_access->p_input ? vlc_object_hold((vlc_object_t *)p_access->p_input) : NULL;
 }
 
+/**
+ * Polls for I/O events or an asynchronous signal. This functions behaves like
+ * the standard poll() function with two exceptions:
+ * - If the provided access object belongs to an input thread, and the input
+ *   thread received a control request since the previous call to
+ *   this function, it will return -1 and set errno to EINTR.
+ * - The function may spuriously return -1 and set errno to EINTR.
+ *
+ * @param access access object
+ * @param fds table specifying the file descriptors and events
+ * @param nfds number of elements in the table
+ * @param timeout timeout (in milliseconds) or -1
+ *
+ * @return Normally, the number of file descriptors with at least one pending
+ * event is returned. In particular, if the timeout is reached without any
+ * events, then zero is returned. On error, -1 is returned.
+ *
+ */
+int vlc_access_poll(access_t *access, struct pollfd fds[], unsigned long nfds,
+                    int timeout_ms)
+{
+    assert(access != NULL);
+
+    input_thread_t *input = access->p_input;
+    int ret;
+
+    do
+    {
+        /* FIXME: do not shorten the timeout */
+        int to = ((unsigned)timeout_ms > 500u) ? 500 : timeout_ms;
+
+        ret = poll(fds, nfds, to);
+
+        /* FIXME: handle other events than killing the input */
+        if (ret == 0 && input != NULL && !vlc_object_alive((vlc_object_t *)input))
+        {
+            errno = EINTR;
+            ret = -1;
+        }
+    }
+    while (ret == 0);
+
+    return ret;
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 7f06ed6..579433b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -482,6 +482,7 @@ video_format_Setup
 video_format_Print
 video_splitter_Delete
 video_splitter_New
+vlc_access_poll
 vlc_b64_decode
 vlc_b64_decode_binary
 vlc_b64_decode_binary_to_buffer



More information about the vlc-commits mailing list