static GSource * create_watch_fd (int fd, GIOCondition cond, GIOFunc func, gpointer data) { GIOChannel *channel; GSource *source; channel = create_io_channel (fd); source = g_io_create_watch (channel, cond); g_source_set_callback (source, (GSourceFunc)func, data, NULL); g_io_channel_unref (channel); return source; }
static gboolean write_input (int fd, const gchar *data, GError **error) { GIOChannel *channel = create_io_channel (fd); GIOStatus status; do { status = g_io_channel_write_chars (channel, data, -1, NULL, error); } while (status == G_IO_STATUS_AGAIN); /* don't care about shutdown errors if we already have an error */ if (status != G_IO_CHANNEL_ERROR) { status = g_io_channel_shutdown(channel, TRUE, error); } else { g_io_channel_shutdown(channel, TRUE, NULL); } return status != G_IO_STATUS_ERROR; }
static GIOChannel * create_write_io_channel (int pipe) { return create_io_channel(pipe, G_IO_FLAG_IS_WRITEABLE); }
static GIOChannel * create_read_io_channel (int pipe) { return create_io_channel(pipe, G_IO_FLAG_IS_READABLE | G_IO_FLAG_NONBLOCK); }