summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2010-07-27 00:03:15 -0700
committerMarcel Holtmann <marcel@holtmann.org>2010-07-27 00:03:15 -0700
commitacf9c645730f2955d289071e188615da414ddcf8 (patch)
tree2931c58fd86a4e2852e9f22e68d8a0c2c13acc0d
parent9dba290c7eaee7d5aa8a00ba536567d665300b1c (diff)
downloadconnman-acf9c645730f2955d289071e188615da414ddcf8.tar.gz
connman-acf9c645730f2955d289071e188615da414ddcf8.tar.bz2
connman-acf9c645730f2955d289071e188615da414ddcf8.zip
Add simple timeout handling for resolver lookups
-rw-r--r--gresolv/gresolv.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gresolv/gresolv.c b/gresolv/gresolv.c
index dad64384..0acff4fe 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;
}