From: Max Kellermann Date: Sun, 19 Mar 2017 10:11:13 +0000 (+0100) Subject: plugin: add plugin_pipe.cycle pointer X-Git-Tag: v0.26~35 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fd22b41f7c6f05373312899b9c7a025610299374;p=ncmpc.git plugin: add plugin_pipe.cycle pointer Replaces the fragile if/else in plugin_data(). --- diff --git a/src/plugin.c b/src/plugin.c index 55de0d3..8701d1e 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -29,6 +29,8 @@ #include struct plugin_pipe { + struct plugin_cycle *cycle; + /** the pipe to the plugin process, or -1 if none is currently open */ int fd; @@ -167,18 +169,13 @@ static gboolean plugin_data(gcc_unused GIOChannel *source, gcc_unused GIOCondition condition, gpointer data) { - struct plugin_cycle *cycle = data; + struct plugin_pipe *p = data; + assert(p->fd >= 0); + + struct plugin_cycle *cycle = p->cycle; assert(cycle != NULL); assert(cycle->pid > 0); - struct plugin_pipe *p = NULL; - if (source == cycle->pipe_stdout.channel) - p = &cycle->pipe_stdout; - else if (source == cycle->pipe_stderr.channel) - p = &cycle->pipe_stderr; - assert(p != NULL); - assert(p->fd >= 0); - char buffer[256]; ssize_t nbytes = condition & G_IO_IN ? read(p->fd, buffer, sizeof(buffer)) @@ -217,6 +214,7 @@ plugin_delayed_fail(gpointer data) static void plugin_fd_add(struct plugin_cycle *cycle, struct plugin_pipe *p, int fd) { + p->cycle = cycle; p->fd = fd; p->data = g_string_new(NULL); p->channel = g_io_channel_unix_new(fd);