diff mbox series

[1/8] gweb: Add TCP connect timeout member and getter/setter.

Message ID E2D57708-0805-45A0-A839-68531357F06D@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Add Configurable Online Check TCP Connect Timeout | expand

Commit Message

Grant Erickson Nov. 11, 2023, 6:58 p.m. UTC
This adds a TCP connect timeout member, getter, and setter. Collectively,
these manage the TCP connection timeout, in milliseconds, for a specified
GWeb object. Connections that take longer than this will be aborted. A
value of zero ('0') indicates that no explicit connection timeout will be
used, leaving the timeout to the underlying operating system and its
network stack.
---
 gweb/gweb.c | 24 ++++++++++++++++++++++++
 gweb/gweb.h |  3 +++
 2 files changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/gweb/gweb.c b/gweb/gweb.c
index 65c075d2128e..bc0aa7a801a6 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -124,6 +124,7 @@  struct _GWeb {
 	char *user_agent_profile;
 	char *http_version;
 	bool close_connection;
+	guint connect_timeout_ms;
 
 	GWebDebugFunc debug_func;
 	gpointer debug_data;
@@ -445,6 +446,29 @@  bool g_web_get_close_connection(GWeb *web)
 	return web->close_connection;
 }
 
+void g_web_set_connect_timeout(GWeb *web, guint timeout_ms)
+{
+	if (!web)
+		return;
+
+	debug(web, "timeout %ums", timeout_ms);
+
+	web->connect_timeout_ms = timeout_ms;
+}
+
+guint g_web_get_connect_timeout(const GWeb *web)
+{
+	guint timeout_ms = 0;
+
+	if (!web)
+		goto done;
+
+	timeout_ms = web->connect_timeout_ms;
+
+done:
+	return timeout_ms;
+}
+
 static inline void call_result_func(struct web_session *session, guint16 status)
 {
 
diff --git a/gweb/gweb.h b/gweb/gweb.h
index 8a6304e3014f..3c50979cfd0a 100644
--- a/gweb/gweb.h
+++ b/gweb/gweb.h
@@ -142,6 +142,9 @@  bool g_web_set_ua_profile(GWeb *web, const char *profile);
 
 bool g_web_set_http_version(GWeb *web, const char *version);
 
+void g_web_set_connect_timeout(GWeb *web, guint timeout_ms);
+guint g_web_get_connect_timeout(const GWeb *web);
+
 void g_web_set_close_connection(GWeb *web, bool enabled);
 bool g_web_get_close_connection(GWeb *web);