[systemd-devel] [PATCH 2/2] [POC] networkd: port to glib main loop
Lennart Poettering
lennart at poettering.net
Wed Aug 20 15:41:32 PDT 2014
On Wed, 20.08.14 17:28, Tom Gundersen (teg at jklm.no) wrote:
I'd really like to see this code reduced to the minimum included in the
man page of the respective sd-event functions, instead of shipping a
library for this.
I think we should be able to make this ridiculously short so that it
could work as an example.
> +static gboolean event_prepare(GSource *source, gint *timeout_) {
> + sd_event *event;
> + int r;
> +
> + assert(source);
> +
> + event = ((SDEventSource *)source)->event;
> +
> + r = sd_event_prepare(event);
> + if (r > 0)
> + return TRUE;
> + else
> + return FALSE;
> +}
This could be shortened to this for the sake of an example:
static gboolean event_prepare(GSource *source, gint *timeout) {
return sd_event_prepare(((SDEventSource*) source)->event) > 0;
}
> +static gboolean event_check(GSource *source) {
> + sd_event *event;
> + int r;
> +
> + assert(source);
> +
> + event = ((SDEventSource *)source)->event;
> +
> + r = sd_event_wait(event, 0);
> + if (r > 0)
> + return TRUE;
> + else
> + return FALSE;
> +}
Similar:
static gboolean event_check(GSource *source) {
return sd_event_wait(((SDEventSOurce*) source)->event) > 0;
}
> +
> +static gboolean event_dispatch(GSource *source, GSourceFunc callback,
> + gpointer user_data) {
> + sd_event *event;
> + int r;
> +
> + assert(source);
> +
> + event = ((SDEventSource *)source)->event;
> +
> + r = sd_event_dispatch(event);
> + if (r < 0)
> + return G_SOURCE_REMOVE;
> + else
> + return G_SOURCE_CONTINUE;
> +}
Similar:
static gboolean event_dispatch(GSource *source, GSourceFunc callback, gpointer userdata) {
return sd_event_dispatch(((SDEventSOurce*) source)->event) < 0 ? G_SOURCE_REMOVE : G_SOURCE_CONTINUE;
}
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list