static gboolean fifo_watch(GIOChannel *gio, GIOCondition condition) { char *line; GIOStatus ret; GError *err = NULL; if (condition & G_IO_HUP) { g_error("fifo: read end of pipe died"); } if (!gio) { g_error("fifo: GIOChannel broken"); } ret = g_io_channel_read_line(gio, &line, NULL, NULL, &err); if (ret == G_IO_STATUS_ERROR) { g_error("fifo: error reading from fifo: %s", err->message); g_error_free(err); } /* simulate the typed flag to allow to record the commands in history */ vb.state.typed = true; map_handle_string(line, true); g_free(line); /* unset typed flag */ vb.state.typed = false; return true; }
static gboolean socket_watch(GIOChannel *chan) { GIOStatus ret; GError *error = NULL; char *line, *inputtext; gsize len; ret = g_io_channel_read_line(chan, &line, &len, NULL, &error); if (ret == G_IO_STATUS_ERROR || ret == G_IO_STATUS_EOF) { if (ret == G_IO_STATUS_ERROR) { g_warning("Error reading: %s", error->message); g_error_free(error); } /* shutdown and remove the client channel */ ret = g_io_channel_shutdown(chan, true, &error); g_io_channel_unref(chan); if (ret == G_IO_STATUS_ERROR) { g_warning("Error closing: %s", error->message); g_error_free(error); } return false; } /* simulate the typed flag to allow to record the commands in history */ vb.state.typed = true; /* run the commands */ map_handle_string(line, true); g_free(line); /* unset typed flag */ vb.state.typed = false; /* We assume that the commands result is still available in the inputbox, * so the whole inputbox content is written to the socket. */ inputtext = vb_get_input_text(); ret = g_io_channel_write_chars(chan, inputtext, -1, &len, &error); if (ret == G_IO_STATUS_ERROR) { g_warning("Error writing: %s", error->message); g_error_free(error); } if (g_io_channel_flush(chan, &error) == G_IO_STATUS_ERROR) { g_warning("Error flushing: %s", error->message); g_error_free(error); } g_free(inputtext); return true; }