[vlc-devel] [PATCH 1/6] os2: filesystem: implement vlc_write() and vlc_writev()

Rémi Denis-Courmont remi at remlab.net
Wed Jun 10 21:14:20 CEST 2015


Le mercredi 10 juin 2015, 12:27:24 KO Myung-Hun a écrit :
> ---
>  src/os2/filesystem.c | 41 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
> 
> diff --git a/src/os2/filesystem.c b/src/os2/filesystem.c
> index b9d03eb..5a22f0b 100644
> --- a/src/os2/filesystem.c
> +++ b/src/os2/filesystem.c
> @@ -38,6 +38,7 @@
>  #include <sys/stat.h>
>  #include <dirent.h>
>  #include <sys/socket.h>
> +#include <signal.h>
> 
>  #include <vlc_common.h>
>  #include <vlc_charset.h>
> @@ -342,6 +343,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);

This is a bit odd considering that the OS/2 thread support code is not calling 
POSIX threads. Not that I´d know OS/2.

> +
> +    return val;
> +}
> +
>  #include <vlc_network.h>
> 
>  /**

-- 
Rémi Denis-Courmont
Remlab T:mi
http://www.remlab.net/




More information about the vlc-devel mailing list