diff mbox series

[6/8] Leverage GWeb connect timeout and 'OnlineCheckConnectTimeout'.

Message ID B2491372-B5AC-4292-9333-8C786CC6FC81@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, 7 p.m. UTC
This leverages both the GWeb TCP connect timeout setter and the newly-
added 'OnlineCheckConnectTimeout' setting to support TCP connect
timeouts different from the underlying operating system and network
stack when so configured.
---
 src/connman.h |  1 +
 src/service.c | 10 ++++++++--
 src/wispr.c   | 14 ++++++++++----
 3 files changed, 19 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/connman.h b/src/connman.h
index d3f2d0139f91..143a087701d8 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -531,6 +531,7 @@  int __connman_wispr_init(void);
 void __connman_wispr_cleanup(void);
 int __connman_wispr_start(struct connman_service *service,
 					enum connman_ipconfig_type type,
+					guint connect_timeout_ms,
 					__connman_wispr_cb_t callback);
 void __connman_wispr_stop(struct connman_service *service);
 
diff --git a/src/service.c b/src/service.c
index 81a1bebdc14b..075f3fba5abe 100644
--- a/src/service.c
+++ b/src/service.c
@@ -58,6 +58,7 @@  static unsigned int vpn_autoconnect_id = 0;
 static struct connman_service *current_default = NULL;
 static bool services_dirty = false;
 static bool enable_online_to_ready_transition = false;
+static unsigned int online_check_connect_timeout_ms = 0;
 static unsigned int online_check_initial_interval = 0;
 static unsigned int online_check_max_interval = 0;
 static const char *online_check_timeout_interval_style = NULL;
@@ -1700,7 +1701,8 @@  static void redo_wispr(struct connman_service *service,
 		service, connman_service_get_identifier(service),
 		type, __connman_ipconfig_type2string(type));
 
-	__connman_wispr_start(service, type, complete_online_check);
+	__connman_wispr_start(service, type,
+			online_check_connect_timeout_ms, complete_online_check);
 
 	// Release the reference to the service taken when
 	// g_timeout_add_seconds was invoked with the callback
@@ -2011,7 +2013,8 @@  void __connman_service_wispr_start(struct connman_service *service,
 		service->online_check_interval_ipv6 =
 					online_check_initial_interval;
 
-	__connman_wispr_start(service, type, complete_online_check);
+	__connman_wispr_start(service, type,
+			online_check_connect_timeout_ms, complete_online_check);
 }
 
 static void address_updated(struct connman_service *service,
@@ -8496,6 +8499,9 @@  int __connman_service_init(void)
 	else
 		online_check_timeout_compute_func = online_check_timeout_compute_geometric;
 
+	online_check_connect_timeout_ms =
+		connman_setting_get_uint("OnlineCheckConnectTimeout");
+
 	online_check_initial_interval =
 		connman_setting_get_uint("OnlineCheckInitialInterval");
 	online_check_max_interval =
diff --git a/src/wispr.c b/src/wispr.c
index 8a5bbdcfe3d8..8618b5158b04 100644
--- a/src/wispr.c
+++ b/src/wispr.c
@@ -861,6 +861,7 @@  static bool wispr_portal_web_result(GWebResult *result, gpointer user_data)
 		goto done;
 	case GWEB_HTTP_STATUS_CODE_BAD_REQUEST:
 	case GWEB_HTTP_STATUS_CODE_NOT_FOUND:
+	case GWEB_HTTP_STATUS_CODE_REQUEST_TIMEOUT:
 		wp_context->cb(wp_context->service, wp_context->type, false);
 
 		break;
@@ -967,7 +968,8 @@  static gboolean no_proxy_callback(gpointer user_data)
 	return FALSE;
 }
 
-static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
+static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context,
+						guint connect_timeout_ms)
 {
 	enum connman_service_proxy_method proxy_method;
 	char *interface = NULL;
@@ -1012,6 +1014,8 @@  static int wispr_portal_detect(struct connman_wispr_portal_context *wp_context)
 	if (getenv("CONNMAN_WEB_DEBUG"))
 		g_web_set_debug(wp_context->web, web_debug, "WEB");
 
+	g_web_set_connect_timeout(wp_context->web, connect_timeout_ms);
+
 	if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
 		g_web_set_address_family(wp_context->web, AF_INET);
 		wp_context->status_url = online_check_ipv4_url;
@@ -1069,15 +1073,17 @@  done:
 
 int __connman_wispr_start(struct connman_service *service,
 					enum connman_ipconfig_type type,
+					guint connect_timeout_ms,
 					__connman_wispr_cb_t callback)
 {
 	struct connman_wispr_portal_context *wp_context = NULL;
 	struct connman_wispr_portal *wispr_portal = NULL;
 	int index, err;
 
-	DBG("service %p (%s) type %d (%s) callback %p",
+	DBG("service %p (%s) type %d (%s) connect_timeout %ums callback %p",
 		service, connman_service_get_identifier(service),
-		type, __connman_ipconfig_type2string(type), callback);
+		type, __connman_ipconfig_type2string(type),
+		connect_timeout_ms, callback);
 
 	if (!wispr_portal_hash || !callback)
 		return -EINVAL;
@@ -1137,7 +1143,7 @@  int __connman_wispr_start(struct connman_service *service,
 	else
 		wispr_portal->ipv6_context = wp_context;
 
-	err = wispr_portal_detect(wp_context);
+	err = wispr_portal_detect(wp_context, connect_timeout_ms);
 	if (err)
 		goto free_wp;
 	return 0;