[vlc-devel] [PATCH 1/6] os2: filesystem: implement vlc_write() and vlc_writev()
KO Myung-Hun
komh78 at gmail.com
Thu Jun 11 12:45:38 CEST 2015
Hi/2.
Rémi Denis-Courmont wrote:
> 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.
>
Yes. But write() and writev() may cause SIGPIPE on OS/2.
>> +
>> + return val;
>> +}
>> +
>> #include <vlc_network.h>
>>
>> /**
>
More information about the vlc-devel
mailing list