[vlc-commits] [Git][videolan/vlc][master] 6 commits: interrupt: reorder code
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Wed Jul 6 16:09:47 UTC 2022
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
ce812ef9 by Rémi Denis-Courmont at 2022-07-03T21:35:07+03:00
interrupt: reorder code
No function changes.
- - - - -
bbf9a6f2 by Rémi Denis-Courmont at 2022-07-03T21:35:07+03:00
interrupt: factor common polling code
- - - - -
2a41077d by Rémi Denis-Courmont at 2022-07-04T12:40:51+03:00
interrupt: prepare to merge identical functions
No functional changes as vlc_poll_file() always returns 1 and has no
side effects.
- - - - -
66bf0d69 by Rémi Denis-Courmont at 2022-07-04T12:43:09+03:00
interrupt: merge identical implementations
No functional changes.
- - - - -
976de0bc by Rémi Denis-Courmont at 2022-07-04T12:51:55+03:00
interrupt: use vlc_writev()
Fixes #27115.
- - - - -
2fdb6af0 by Rémi Denis-Courmont at 2022-07-04T12:52:09+03:00
win32: implement vlc_{recv,send}msg_i11e()
- - - - -
1 changed file:
- src/misc/interrupt.c
Changes:
=====================================
src/misc/interrupt.c
=====================================
@@ -279,6 +279,12 @@ int vlc_interrupt_forward_stop(void *const data[2])
}
#ifndef _WIN32
+# include <fcntl.h>
+# include <sys/uio.h>
+# ifdef HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+# endif
+
static void vlc_poll_i11e_wake(void *opaque)
{
uint64_t value = 1;
@@ -392,12 +398,89 @@ int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
return ret;
}
-# include <fcntl.h>
-# include <sys/uio.h>
-# ifdef HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-# endif
+static int vlc_poll_file(int fd, unsigned int mask)
+{
+ struct pollfd ufd;
+
+ ufd.fd = fd;
+ ufd.events = mask;
+ return vlc_poll_i11e(&ufd, 1, -1);
+}
+
+static int vlc_poll_sock(int sock, unsigned int mask)
+{
+ return vlc_poll_file(sock, mask);
+}
+
+#else /* !_WIN32 */
+static void CALLBACK vlc_poll_i11e_wake_self(ULONG_PTR data)
+{
+ (void) data; /* Nothing to do */
+}
+
+static void vlc_poll_i11e_wake(void *opaque)
+{
+ HANDLE th = opaque;
+ QueueUserAPC(vlc_poll_i11e_wake_self, th, 0);
+}
+
+static void vlc_poll_i11e_cleanup(void *opaque)
+{
+ vlc_interrupt_t *ctx = opaque;
+ HANDLE th = ctx->data;
+
+ vlc_interrupt_finish(ctx);
+ CloseHandle(th);
+}
+
+int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
+{
+ vlc_interrupt_t *ctx = vlc_interrupt_var;
+ if (ctx == NULL)
+ return vlc_poll(fds, nfds, timeout);
+
+ int ret = -1;
+ HANDLE th;
+
+ if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
+ GetCurrentProcess(), &th, 0, FALSE,
+ DUPLICATE_SAME_ACCESS))
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ vlc_interrupt_prepare(ctx, vlc_poll_i11e_wake, th);
+
+ vlc_cleanup_push(vlc_poll_i11e_cleanup, ctx);
+ ret = vlc_poll(fds, nfds, timeout);
+ vlc_cleanup_pop();
+
+ if (vlc_interrupt_finish(ctx))
+ {
+ errno = EINTR;
+ ret = -1;
+ }
+ CloseHandle(th);
+ return ret;
+}
+
+static int vlc_poll_file(int fd, unsigned int mask)
+{
+ (void) fd; (void) mask;
+ return 1;
+}
+
+static int vlc_poll_sock(int sock, unsigned int mask)
+{
+ struct pollfd ufd;
+
+ ufd.fd = sock;
+ ufd.events = mask;
+ return vlc_poll_i11e(&ufd, 1, -1);
+}
+#endif /* _WIN32 */
/* There are currently no ways to atomically force a non-blocking read or write
* operations. Even for sockets, the MSG_DONTWAIT flag is non-standard.
@@ -413,12 +496,7 @@ int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
*/
ssize_t vlc_readv_i11e(int fd, struct iovec *iov, int count)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLIN;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_file(fd, POLLIN) < 0)
return -1;
return readv(fd, iov, count);
}
@@ -432,16 +510,10 @@ ssize_t vlc_readv_i11e(int fd, struct iovec *iov, int count)
*/
ssize_t vlc_writev_i11e(int fd, const struct iovec *iov, int count)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLOUT;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_file(fd, POLLOUT) < 0)
return -1;
- return writev(fd, iov, count);
+ return vlc_writev(fd, iov, count);
}
-#endif
/**
* Wrapper for read() that returns the EINTR error upon VLC I/O interruption.
@@ -466,21 +538,16 @@ ssize_t vlc_write_i11e(int fd, const void *buf, size_t count)
return vlc_writev_i11e(fd, &iov, 1);
}
-#ifndef _WIN32
ssize_t vlc_recvmsg_i11e(int fd, struct msghdr *msg, int flags)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLIN;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_sock(fd, POLLIN) < 0)
return -1;
/* NOTE: MSG_OOB and MSG_PEEK should work fine here.
* MSG_WAITALL is not supported at this point. */
return recvmsg(fd, msg, flags);
}
+#ifndef _WIN32
ssize_t vlc_recvfrom_i11e(int fd, void *buf, size_t len, int flags,
struct sockaddr *addr, socklen_t *addrlen)
{
@@ -497,20 +564,17 @@ ssize_t vlc_recvfrom_i11e(int fd, void *buf, size_t len, int flags,
*addrlen = msg.msg_namelen;
return ret;
}
+#endif
ssize_t vlc_sendmsg_i11e(int fd, const struct msghdr *msg, int flags)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLOUT;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_sock(fd, POLLOUT) < 0)
return -1;
/* NOTE: MSG_EOR and MSG_OOB should all work fine here. */
return vlc_sendmsg(fd, msg, flags);
}
+#ifndef _WIN32
ssize_t vlc_sendto_i11e(int fd, const void *buf, size_t len, int flags,
const struct sockaddr *addr, socklen_t addrlen)
{
@@ -528,97 +592,17 @@ ssize_t vlc_sendto_i11e(int fd, const void *buf, size_t len, int flags,
int vlc_accept_i11e(int fd, struct sockaddr *addr, socklen_t *addrlen,
bool nonblock)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLIN;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_sock(fd, POLLIN) < 0)
return -1;
-
return vlc_accept(fd, addr, addrlen, nonblock);
}
#else /* _WIN32 */
-static void CALLBACK vlc_poll_i11e_wake_self(ULONG_PTR data)
-{
- (void) data; /* Nothing to do */
-}
-
-static void vlc_poll_i11e_wake(void *opaque)
-{
- HANDLE th = opaque;
- QueueUserAPC(vlc_poll_i11e_wake_self, th, 0);
-}
-
-static void vlc_poll_i11e_cleanup(void *opaque)
-{
- vlc_interrupt_t *ctx = opaque;
- HANDLE th = ctx->data;
-
- vlc_interrupt_finish(ctx);
- CloseHandle(th);
-}
-
-int vlc_poll_i11e(struct pollfd *fds, unsigned nfds, int timeout)
-{
- vlc_interrupt_t *ctx = vlc_interrupt_var;
- if (ctx == NULL)
- return vlc_poll(fds, nfds, timeout);
-
- int ret = -1;
- HANDLE th;
-
- if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
- GetCurrentProcess(), &th, 0, FALSE,
- DUPLICATE_SAME_ACCESS))
- {
- errno = ENOMEM;
- return -1;
- }
-
- vlc_interrupt_prepare(ctx, vlc_poll_i11e_wake, th);
-
- vlc_cleanup_push(vlc_poll_i11e_cleanup, ctx);
- ret = vlc_poll(fds, nfds, timeout);
- vlc_cleanup_pop();
-
- if (vlc_interrupt_finish(ctx))
- {
- errno = EINTR;
- ret = -1;
- }
-
- CloseHandle(th);
- return ret;
-}
-
-ssize_t vlc_readv_i11e(int fd, struct iovec *iov, int count)
-{
- return readv(fd, iov, count);
-}
-
-ssize_t vlc_writev_i11e(int fd, const struct iovec *iov, int count)
-{
- return writev(fd, iov, count);
-}
-
-ssize_t vlc_recvmsg_i11e(int fd, struct msghdr *msg, int flags)
-{
- (void) fd; (void) msg; (void) flags;
- vlc_assert_unreachable();
-}
-
ssize_t vlc_recvfrom_i11e(int fd, void *buf, size_t len, int flags,
struct sockaddr *addr, socklen_t *addrlen)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLIN;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_sock(fd, POLLIN) < 0)
return -1;
ssize_t ret = recvfrom(fd, buf, len, flags, addr, addrlen);
@@ -627,21 +611,10 @@ ssize_t vlc_recvfrom_i11e(int fd, void *buf, size_t len, int flags,
return ret;
}
-ssize_t vlc_sendmsg_i11e(int fd, const struct msghdr *msg, int flags)
-{
- (void) fd; (void) msg; (void) flags;
- vlc_assert_unreachable();
-}
-
ssize_t vlc_sendto_i11e(int fd, const void *buf, size_t len, int flags,
const struct sockaddr *addr, socklen_t addrlen)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLOUT;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_sock(fd, POLLOUT) < 0)
return -1;
ssize_t ret = sendto(fd, buf, len, flags, addr, addrlen);
@@ -653,12 +626,7 @@ ssize_t vlc_sendto_i11e(int fd, const void *buf, size_t len, int flags,
int vlc_accept_i11e(int fd, struct sockaddr *addr, socklen_t *addrlen,
bool nonblock)
{
- struct pollfd ufd;
-
- ufd.fd = fd;
- ufd.events = POLLIN;
-
- if (vlc_poll_i11e(&ufd, 1, -1) < 0)
+ if (vlc_poll_sock(fd, POLLIN) < 0)
return -1;
int cfd = vlc_accept(fd, addr, addrlen, nonblock);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d7d51df095b1883d40856c5c315280dec495ea7a...2fdb6af01b38062098368149174ef13fa349a2de
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d7d51df095b1883d40856c5c315280dec495ea7a...2fdb6af01b38062098368149174ef13fa349a2de
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list