diff --git a/include/libwebsockets/lws-system.h b/include/libwebsockets/lws-system.h index f3b216c4d..7b2240515 100644 --- a/include/libwebsockets/lws-system.h +++ b/include/libwebsockets/lws-system.h @@ -322,6 +322,9 @@ lws_dhcpc_status(struct lws_context *context, lws_sockaddr46 *sa46); LWS_EXTERN LWS_VISIBLE int lws_system_cpd_start(struct lws_context *context); +LWS_EXTERN LWS_VISIBLE void +lws_system_cpd_start_defer(struct lws_context *cx, lws_usec_t defer_us); + /** * lws_system_cpd_set() - report the result of the captive portal detection diff --git a/lib/core-net/client/connect2.c b/lib/core-net/client/connect2.c index 6db6ba95c..77594cef8 100644 --- a/lib/core-net/client/connect2.c +++ b/lib/core-net/client/connect2.c @@ -70,11 +70,17 @@ lws_getaddrinfo46(struct lws *wsi, const char *ads, struct addrinfo **result) #endif #if defined(EAI_FAIL) || n == EAI_FAIL +#endif +#if defined(EAI_AGAIN) + || n == EAI_AGAIN #endif ) { +#if defined(LWS_WITH_SECURE_STREAMS) + +#endif wsi->dns_reachability = 1; - lwsl_notice("%s: asking to recheck CPD\n", __func__); - lws_system_cpd_start(wsi->a.context); + lwsl_notice("%s: asking to recheck CPD in 1ms\n", __func__); + lws_system_cpd_start_defer(wsi->a.context, LWS_US_PER_MS); } lwsl_info("%s: getaddrinfo '%s' says %d\n", __func__, ads, n); diff --git a/lib/core/context.c b/lib/core/context.c index 822623ef3..d2a7a9ef8 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -1401,6 +1401,22 @@ lws_system_cpd_start(struct lws_context *cx) #endif } +static void +lws_system_deferred_cb(lws_sorted_usec_list_t *sul) +{ + struct lws_context *cx = + lws_container_of(sul, struct lws_context, sul_cpd_defer); + + lws_system_cpd_start(cx); +} + +void +lws_system_cpd_start_defer(struct lws_context *cx, lws_usec_t defer_us) +{ + lws_sul_schedule(cx, 0, &cx->sul_cpd_defer, + lws_system_deferred_cb, defer_us); +} + static const char *cname[] = { "Unknown", "OK", "Captive", "No internet" }; void diff --git a/lib/core/private-lib-core.h b/lib/core/private-lib-core.h index 5e141b14e..e713b064e 100644 --- a/lib/core/private-lib-core.h +++ b/lib/core/private-lib-core.h @@ -397,6 +397,7 @@ struct lws_context { #if defined(LWS_WITH_SECURE_STREAMS) struct lws_ss_handle *ss_cpd; #endif + lws_sorted_usec_list_t sul_cpd_defer; #if defined(LWS_WITH_NETWORK) struct lws_context_per_thread pt[LWS_MAX_SMP];