diff options
author | wm4 <wm4@nowhere> | 2014-12-24 13:18:00 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-12-24 13:18:00 +0100 |
commit | 98a80884da100eaee283447a0380c761b15266c7 (patch) | |
tree | 2ffa46163f2d83e0e85283c31d30a18a297ca9db /input/ipc.c | |
parent | 5640c195a9ebd206cf2a1556e59eb7cae35b8d03 (diff) | |
download | mpv-98a80884da100eaee283447a0380c761b15266c7.tar.bz2 mpv-98a80884da100eaee283447a0380c761b15266c7.tar.xz |
ipc: report some user errors better
Using the IPC with a program, it's not often obvious that a newline must
be sent to terminate a command. Print a warning if the connection is
closed while there is still uninterpreted data in the buffer.
Print the OS reported error if reading/writing the socket fails. Print
an erro if JSON parsing fails.
I considered silencing write errors if the write end is closed (EPIPE),
because a client might send a bunch of commands, and then close the
socket without wanting to read the reply. But then, mpv disconnects
without reading further commands that might still be buffered, so it's
probably a good idea to always print the error.
Diffstat (limited to 'input/ipc.c')
-rw-r--r-- | input/ipc.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/input/ipc.c b/input/ipc.c index 7d15ac84d0..4fd9cf17e1 100644 --- a/input/ipc.c +++ b/input/ipc.c @@ -243,6 +243,7 @@ static char *json_execute_command(struct client_arg *arg, void *ta_parent, rc = json_parse(ta_parent, &msg_node, &src, 3); if (rc < 0) { + MP_ERR(arg, "malformed JSON received\n"); rc = MPV_ERROR_INVALID_PARAMETER; goto error; } @@ -546,7 +547,7 @@ static void *client_thread(void *p) if (errno == EAGAIN) break; - MP_ERR(arg, "Read error\n"); + MP_ERR(arg, "Read error (%s)\n", mp_strerror(errno)); goto done; } @@ -582,7 +583,7 @@ static void *client_thread(void *p) rc = ipc_write(arg->client_fd, reply_msg, strlen(reply_msg)); if (rc < 0) { - MP_ERR(arg, "Write error\n"); + MP_ERR(arg, "Write error (%s)\n", mp_strerror(errno)); talloc_free(tmp); goto done; } @@ -595,6 +596,8 @@ static void *client_thread(void *p) } done: + if (client_msg.len > 0) + MP_WARN(arg, "Ignoring unterminated command on disconnect.\n"); talloc_free(client_msg.start); if (arg->close_client_fd) close(arg->client_fd); |