From fd22b41f7c6f05373312899b9c7a025610299374 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 19 Mar 2017 11:11:13 +0100 Subject: [PATCH] plugin: add plugin_pipe.cycle pointer Replaces the fragile if/else in plugin_data(). --- src/plugin.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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); -- 2.30.2