summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-26 22:06:40 +0100
committerwm4 <wm4@nowhere>2015-02-26 22:09:00 +0100
commitf47beb1f07f2dff56202d1d6772de75f3c09b780 (patch)
tree7a0708733b4a0e09daeb45e0e3dd6ae6101c0971 /input
parent7b02c79a2367d0baf565f8550c65a5f4bcd92552 (diff)
downloadmpv-f47beb1f07f2dff56202d1d6772de75f3c09b780.tar.bz2
mpv-f47beb1f07f2dff56202d1d6772de75f3c09b780.tar.xz
input: if FD is not writable, just don't write to the FD
This is for the case if the FD is a uni-directional pipe.
Diffstat (limited to 'input')
-rw-r--r--input/ipc.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/input/ipc.c b/input/ipc.c
index d90922f80a..e983a74c08 100644
--- a/input/ipc.c
+++ b/input/ipc.c
@@ -482,14 +482,20 @@ static char *text_execute_command(struct client_arg *arg, void *tmp, char *src)
return NULL;
}
-static int ipc_write(int fd, const char *buf, size_t count)
+static int ipc_write_str(struct client_arg *client, const char *buf)
{
+ size_t count = strlen(buf);
while (count > 0) {
- ssize_t rc = write(fd, buf, count);
+ ssize_t rc = write(client->client_fd, buf, count);
if (rc <= 0) {
if (rc == 0)
return -1;
+ if (errno == EBADF) {
+ client->writable = false;
+ return 0;
+ }
+
if (errno == EINTR)
continue;
@@ -567,10 +573,10 @@ static void *client_thread(void *p)
goto done;
}
- rc = ipc_write(arg->client_fd, event_msg, strlen(event_msg));
+ rc = ipc_write_str(arg, event_msg);
talloc_free(event_msg);
if (rc < 0) {
- MP_ERR(arg, "Write error\n");
+ MP_ERR(arg, "Write error (%s)\n", mp_strerror(errno));
goto done;
}
}
@@ -619,8 +625,7 @@ static void *client_thread(void *p)
}
if (reply_msg && arg->writable) {
- rc = ipc_write(arg->client_fd, reply_msg,
- strlen(reply_msg));
+ rc = ipc_write_str(arg, reply_msg);
if (rc < 0) {
MP_ERR(arg, "Write error (%s)\n", mp_strerror(errno));
talloc_free(tmp);