mirror of
https://github.com/mpv-player/mpv
synced 2025-01-29 19:22:48 +00:00
input: separate wakeup pipe creation into a separate function
Error handling is slightly reduced: we assume that setting a pipe to non-blocking can never fail.
This commit is contained in:
parent
5929dc458f
commit
ec18df8466
@ -1492,20 +1492,9 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
||||
}
|
||||
|
||||
#ifndef __MINGW32__
|
||||
int ret = pipe(ictx->wakeup_pipe);
|
||||
if (ret == 0) {
|
||||
for (int i = 0; i < 2 && ret >= 0; i++) {
|
||||
mp_set_cloexec(ictx->wakeup_pipe[i]);
|
||||
ret = fcntl(ictx->wakeup_pipe[i], F_GETFL);
|
||||
if (ret < 0)
|
||||
break;
|
||||
ret = fcntl(ictx->wakeup_pipe[i], F_SETFL, ret | O_NONBLOCK);
|
||||
if (ret < 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
int ret = mp_make_wakeup_pipe(ictx->wakeup_pipe);
|
||||
if (ret < 0)
|
||||
MP_ERR(ictx, "Failed to initialize wakeup pipe: %s\n", strerror(errno));
|
||||
MP_ERR(ictx, "Failed to initialize wakeup pipe: %s\n", strerror(-ret));
|
||||
else
|
||||
mp_input_add_fd(ictx, ictx->wakeup_pipe[0], true, NULL, read_wakeup,
|
||||
NULL, NULL);
|
||||
|
25
osdep/io.c
25
osdep/io.c
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "talloc.h"
|
||||
|
||||
@ -41,6 +42,30 @@ bool mp_set_cloexec(int fd)
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
int mp_make_wakeup_pipe(int pipes[2])
|
||||
{
|
||||
pipes[0] = pipes[1] = -1;
|
||||
return -ENOSYS;
|
||||
}
|
||||
#else
|
||||
// create a pipe, and set it to non-blocking (and also set FD_CLOEXEC)
|
||||
int mp_make_wakeup_pipe(int pipes[2])
|
||||
{
|
||||
if (pipe(pipes) != 0) {
|
||||
pipes[0] = pipes[1] = -1;
|
||||
return -errno;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mp_set_cloexec(pipes[i]);
|
||||
int val = fcntl(pipes[i], F_GETFL) | O_NONBLOCK;
|
||||
fcntl(pipes[i], F_SETFL, val);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
@ -44,6 +44,7 @@
|
||||
#endif
|
||||
|
||||
bool mp_set_cloexec(int fd);
|
||||
int mp_make_wakeup_pipe(int pipes[2]);
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <wchar.h>
|
||||
|
Loading…
Reference in New Issue
Block a user