[vlc-commits] os2: filesystem: implement vlc_write() and vlc_writev()

KO Myung-Hun git at videolan.org
Fri Jun 12 21:22:38 CEST 2015


vlc | branch: master | KO Myung-Hun <komh78 at gmail.com> | Wed Jun 10 12:27:24 2015 +0900| [c8c7d545866d2c44ac98c10f09b73bcc0d0abd4c] | committer: Rémi Denis-Courmont

os2: filesystem: implement vlc_write() and vlc_writev()

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

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

 src/os2/filesystem.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/os2/filesystem.c b/src/os2/filesystem.c
index 0c92c5c..51a4447 100644
--- a/src/os2/filesystem.c
+++ b/src/os2/filesystem.c
@@ -39,6 +39,7 @@
 #include <sys/stat.h>
 #include <dirent.h>
 #include <sys/socket.h>
+#include <signal.h>
 
 #include <vlc_common.h>
 #include <vlc_charset.h>
@@ -346,6 +347,46 @@ int vlc_pipe (int fds[2])
     return 0;
 }
 
+/**
+ * Writes data to a file descriptor. Unlike write(), if EPIPE error occurs,
+ * this function does not generate a SIGPIPE signal.
+ * @note If the file descriptor is known to be neither a pipe/FIFO nor a
+ * connection-oriented socket, the normal write() should be used.
+ */
+ssize_t vlc_write(int fd, const void *buf, size_t len)
+{
+    struct iovec iov = { .iov_base = (void *)buf, .iov_len = len };
+
+    return vlc_writev(fd, &iov, 1);
+}
+
+/**
+ * Writes data from an iovec structure to a file descriptor. Unlike writev(),
+ * if EPIPE error occurs, this function does not generate a SIGPIPE signal.
+ */
+ssize_t vlc_writev(int fd, const struct iovec *iov, int count)
+{
+    sigset_t set, oset;
+
+    sigemptyset(&set);
+    sigaddset(&set, SIGPIPE);
+    pthread_sigmask(SIG_BLOCK, &set, &oset);
+
+    ssize_t val = writev(fd, iov, count);
+    if (val < 0 && errno == EPIPE)
+    {
+        siginfo_t info;
+        struct timespec ts = { 0, 0 };
+
+        while (sigtimedwait(&set, &info, &ts) >= 0 || errno != EAGAIN);
+    }
+
+    if (!sigismember(&oset, SIGPIPE)) /* Restore the signal mask if changed */
+        pthread_sigmask(SIG_SETMASK, &oset, NULL);
+
+    return val;
+}
+
 #include <vlc_network.h>
 
 /**



More information about the vlc-commits mailing list