From: Marcel Holtmann Date: Tue, 27 Jul 2010 07:03:15 +0000 (-0700) Subject: Add simple timeout handling for resolver lookups X-Git-Tag: 0.56~91 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=acf9c645730f2955d289071e188615da414ddcf8;p=platform%2Fupstream%2Fconnman.git Add simple timeout handling for resolver lookups --- diff --git a/gresolv/gresolv.c b/gresolv/gresolv.c index dad6438..0acff4f 100644 --- a/gresolv/gresolv.c +++ b/gresolv/gresolv.c @@ -35,7 +35,10 @@ #include "gresolv.h" struct resolv_query { + GResolv *resolv; + guint id; + guint timeout; uint16_t msgid; @@ -85,9 +88,29 @@ static inline void debug(GResolv *resolv, const char *format, ...) static void destroy_query(struct resolv_query *query) { + if (query->timeout > 0) + g_source_remove(query->timeout); + g_free(query); } +static gboolean query_timeout(gpointer user_data) +{ + struct resolv_query *query = user_data; + GResolv *resolv = query->resolv; + + query->timeout = 0; + + if (query->result_func != NULL) + query->result_func(G_RESOLV_STATUS_ERROR, + NULL, query->result_data); + + destroy_query(query); + g_queue_remove(resolv->query_queue, query); + + return FALSE; +} + static void free_nameserver(struct resolv_nameserver *nameserver) { if (nameserver == NULL) @@ -408,7 +431,11 @@ guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname, return -EIO; } + query->resolv = resolv; + g_queue_push_tail(resolv->query_queue, query); + query->timeout = g_timeout_add_seconds(5, query_timeout, query); + return 0; }