# HG changeset patch # User Mikael Hallendal # Date 1215988525 -7200 # Node ID e6e0a95d108adc5c12724b9ffa87642f0297c76a # Parent 0cd193ceddaa02a9bda89dd09d4e985afd649a70 Implemented the idle "spawn" in LmBlockingResolver. In order to simulate the asynchronous API of LmResolver the synchronous LmBlockingResolver runs in an idle callback. That means the lm_resolver_lookup call will return just as it does in the asynchronous version and instead the result will come through the given callback. diff -r 0cd193ceddaa -r e6e0a95d108a loudmouth/lm-blocking-resolver.c --- a/loudmouth/lm-blocking-resolver.c Mon Jul 14 00:14:28 2008 +0200 +++ b/loudmouth/lm-blocking-resolver.c Mon Jul 14 00:35:25 2008 +0200 @@ -27,7 +27,7 @@ typedef struct LmBlockingResolverPriv LmBlockingResolverPriv; struct LmBlockingResolverPriv { - gint my_prop; + guint idle_id; }; static void blocking_resolver_finalize (GObject *object); @@ -56,7 +56,6 @@ LmBlockingResolverPriv *priv; priv = GET_PRIV (blocking_resolver); - } static void @@ -69,13 +68,41 @@ (G_OBJECT_CLASS (lm_blocking_resolver_parent_class)->finalize) (object); } +static gboolean +blocking_resolver_idle_lookup (LmBlockingResolver *resolver) +{ + LmBlockingResolverPriv *priv = GET_PRIV (resolver); + + /* Start the DNS querying */ + + priv->idle_id = 0; + return FALSE; +} + static void blocking_resolver_lookup (LmResolver *resolver) { + LmBlockingResolverPriv *priv; + + g_return_if_fail (LM_IS_BLOCKING_RESOLVER (resolver)); + + priv = GET_PRIV (resolver); + + priv->idle_id = g_idle_add ((GSourceFunc) blocking_resolver_idle_lookup, + resolver); } static void blocking_resolver_cancel (LmResolver *resolver) { + LmBlockingResolverPriv *priv; + + g_return_if_fail (LM_IS_BLOCKING_RESOLVER (resolver)); + + priv = GET_PRIV (resolver); + + if (priv->idle_id > 0) { + g_source_remove (priv->idle_id); + priv->idle_id = 0; + } } -