diff mbox series

[05/12] gresolv: Add generic error for GResolv struct with getter

Message ID 20250124185916.1546471-6-jussi.laakkonen@jolla.com (mailing list archive)
State New
Headers show
Series Improve WireGuard disconnect, error and hostname lookup | expand

Commit Message

Jussi Laakkonen Jan. 24, 2025, 6:59 p.m. UTC
Add a error for the struct to be used with hostname lookup. The function
should return either 0 in case of error or the source id, this fixes the
wrong returns when error happens and makes it possible to retrieve the
error afterwards.
---
 gweb/gresolv.c | 15 +++++++++++++--
 gweb/gresolv.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/gweb/gresolv.c b/gweb/gresolv.c
index 8101d718..1f1db474 100644
--- a/gweb/gresolv.c
+++ b/gweb/gresolv.c
@@ -116,6 +116,7 @@  struct _GResolv {
 
 	GResolvDebugFunc debug_func;
 	gpointer debug_data;
+	int err;
 };
 
 #define debug(resolv, format, arg...)				\
@@ -1060,7 +1061,8 @@  guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
 	if (resolv->result_family != AF_INET6) {
 		if (add_query(lookup, hostname, ns_t_a)) {
 			g_free(lookup);
-			return -EIO;
+			resolv->err = -EIO;
+			return 0;
 		}
 	}
 
@@ -1073,7 +1075,8 @@  guint g_resolv_lookup_hostname(GResolv *resolv, const char *hostname,
 			}
 
 			g_free(lookup);
-			return -EIO;
+			resolv->err = -EIO;
+			return 0;
 		}
 	}
 
@@ -1119,3 +1122,11 @@  bool g_resolv_set_address_family(GResolv *resolv, int family)
 
 	return true;
 }
+
+int g_resolv_get_error(GResolv *resolv)
+{
+	if (!resolv)
+		return 0;
+
+	return resolv->err;
+}
diff --git a/gweb/gresolv.h b/gweb/gresolv.h
index 5e82c168..1994ac34 100644
--- a/gweb/gresolv.h
+++ b/gweb/gresolv.h
@@ -71,6 +71,8 @@  bool g_resolv_cancel_lookup(GResolv *resolv, guint id);
 
 bool g_resolv_set_address_family(GResolv *resolv, int family);
 
+int g_resolv_get_error(GResolv *resolv);
+
 #ifdef __cplusplus
 }
 #endif