static gboolean cb_source_dispatch (GSource *source, GSourceFunc unused, gpointer user_data) { CallbackSource *cb_source = (CallbackSource*)source; GPollFD *poll; gint i; /* Standard input */ poll = &cb_source->polls[0]; if (poll->fd >= 0 && poll->revents != 0) { g_assert (cb_source->callbacks.standard_input); if (!(cb_source->callbacks.standard_input) (poll->fd, user_data)) close_poll (source, poll); } /* Standard output */ poll = &cb_source->polls[1]; if (poll->fd >= 0 && poll->revents != 0) { g_assert (cb_source->callbacks.standard_output); if (!(cb_source->callbacks.standard_output) (poll->fd, user_data)) close_poll (source, poll); } /* Standard error */ poll = &cb_source->polls[2]; if (poll->fd >= 0 && poll->revents != 0) { g_assert (cb_source->callbacks.standard_error); if (!(cb_source->callbacks.standard_error) (poll->fd, user_data)) close_poll (source, poll); } for (i = 0; i < 3; ++i) { if (cb_source->polls[i].fd >= 0) return TRUE; } /* All input and output is done */ if (cb_source->callbacks.completed) (cb_source->callbacks.completed) (user_data); return FALSE; }
static gboolean on_gnupg_source_dispatch (GSource *source, GSourceFunc unused, gpointer user_data) { GnupgSource *gnupg_source = (GnupgSource*)source; GcrGnupgProcess *self = gnupg_source->process; GPollFD *poll; guint i; /* Standard input, no support yet */ poll = &gnupg_source->polls[FD_INPUT]; if (poll->fd >= 0) { if (poll->revents & G_IO_OUT) if (!on_gnupg_source_input (self, gnupg_source, poll->fd)) poll->revents |= G_IO_HUP; if (poll->revents & G_IO_HUP) close_poll (source, poll); poll->revents = 0; } /* Status output */ poll = &gnupg_source->polls[FD_STATUS]; if (poll->fd >= 0) { if (poll->revents & G_IO_IN) if (!on_gnupg_source_status (self, gnupg_source, poll->fd)) poll->revents |= G_IO_HUP; if (poll->revents & G_IO_HUP) close_poll (source, poll); poll->revents = 0; } /* Attribute output */ poll = &gnupg_source->polls[FD_ATTRIBUTE]; if (poll->fd >= 0) { if (poll->revents & G_IO_IN) if (!on_gnupg_source_attribute (self, gnupg_source, poll->fd)) poll->revents |= G_IO_HUP; if (poll->revents & G_IO_HUP) close_poll (source, poll); poll->revents = 0; } /* Standard output */ poll = &gnupg_source->polls[FD_OUTPUT]; if (poll->fd >= 0) { if (poll->revents & G_IO_IN) if (!on_gnupg_source_output (self, gnupg_source, poll->fd)) poll->revents |= G_IO_HUP; if (poll->revents & G_IO_HUP) close_poll (source, poll); poll->revents = 0; } /* Standard error */ poll = &gnupg_source->polls[FD_ERROR]; if (poll->fd >= 0) { if (poll->revents & G_IO_IN) if (!on_gnupg_source_error (self, gnupg_source, poll->fd, (poll->revents & G_IO_HUP) ? TRUE : FALSE)) poll->revents |= G_IO_HUP; if (poll->revents & G_IO_HUP) close_poll (source, poll); poll->revents = 0; } for (i = 0; i < NUM_FDS; ++i) { if (gnupg_source->polls[i].fd >= 0) return TRUE; } /* Because we return below */ self->pv->source_sig = 0; if (!gnupg_source->child_pid) complete_source_is_done (gnupg_source); return FALSE; /* Disconnect this source */ }