summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2011-05-04 18:51:36 +0300
committerUoti Urpala <uau@mplayer2.org>2011-05-04 18:53:17 +0300
commit618f760866441a01051a0177529c7524082f4e37 (patch)
treef93381a89eb9a1a173b6a7f156ab7b719809c0fe
parent0fff1380b18f4f695d0481fd0cb0e19e1991140a (diff)
downloadmpv-618f760866441a01051a0177529c7524082f4e37.tar.bz2
mpv-618f760866441a01051a0177529c7524082f4e37.tar.xz
input: make slave command file descriptors nonblocking
Neither fd 0 slave input (-slave) nor additional opened fds (-input file=X) were set to nonblocking mode as they should have been. Fix. Also rename the horribly generic USE_SELECT #define used for a specific slave input detail.
-rw-r--r--input/input.c4
-rw-r--r--mplayer.c10
-rw-r--r--osdep/getch2.h4
3 files changed, 12 insertions, 6 deletions
diff --git a/input/input.c b/input/input.c
index 808b197603..567a801ca7 100644
--- a/input/input.c
+++ b/input/input.c
@@ -1838,12 +1838,12 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf)
if (input_conf->in_file) {
struct stat st;
- int mode = O_RDONLY;
+ int mode = O_RDONLY | O_NONBLOCK;
// Use RDWR for FIFOs to ensure they stay open over multiple accesses.
// Note that on Windows stat may fail for named pipes,
// but due to how the API works, using RDONLY should be ok.
if (stat(input_conf->in_file, &st) == 0 && S_ISFIFO(st.st_mode))
- mode = O_RDWR;
+ mode = O_RDWR | O_NONBLOCK;
int in_file_fd = open(input_conf->in_file, mode);
if (in_file_fd >= 0)
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL,
diff --git a/mplayer.c b/mplayer.c
index 6730bc3cbf..f988d92d1b 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -4030,8 +4030,14 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){
current_module = "init_input";
mpctx->input = mp_input_init(&opts->input);
mp_input_add_key_fd(mpctx->input, -1,0,mplayer_get_key,NULL, mpctx->key_fifo);
-if(slave_mode)
- mp_input_add_cmd_fd(mpctx->input, 0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL);
+ if(slave_mode) {
+#if USE_FD0_CMD_SELECT
+ int flags = fcntl(0, F_GETFL);
+ if (flags != -1)
+ fcntl(0, F_SETFL, flags | O_NONBLOCK);
+#endif
+ mp_input_add_cmd_fd(mpctx->input, 0,USE_FD0_CMD_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL);
+ }
else if (opts->consolecontrols)
mp_input_add_key_fd(mpctx->input, 0, 1, read_keys, NULL, mpctx->key_fifo);
// Set the libstream interrupt callback
diff --git a/osdep/getch2.h b/osdep/getch2.h
index 7ee40d9e98..8fb346d4f7 100644
--- a/osdep/getch2.h
+++ b/osdep/getch2.h
@@ -61,10 +61,10 @@ char *get_term_charset(void);
#if defined(__MINGW32__) || defined(__OS2__)
/* slave cmd function for Windows and OS/2 */
int mp_input_slave_cmd_func(int fd,char* dest,int size);
-#define USE_SELECT 0
+#define USE_FD0_CMD_SELECT 0
#define MP_INPUT_SLAVE_CMD_FUNC mp_input_slave_cmd_func
#else
-#define USE_SELECT 1
+#define USE_FD0_CMD_SELECT 1
#define MP_INPUT_SLAVE_CMD_FUNC NULL
#endif