mirror of https://github.com/mpv-player/mpv
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.
This commit is contained in:
parent
5640c195a9
commit
98a80884da
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue