1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00

cpd: lws_system_cpd_start_defer

This commit is contained in:
Andy Green 2021-01-07 18:48:33 +00:00
parent 60b5ca649e
commit c86e1c5b56
4 changed files with 28 additions and 2 deletions
include/libwebsockets
lib

View file

@ -322,6 +322,9 @@ lws_dhcpc_status(struct lws_context *context, lws_sockaddr46 *sa46);
LWS_EXTERN LWS_VISIBLE int LWS_EXTERN LWS_VISIBLE int
lws_system_cpd_start(struct lws_context *context); 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 * lws_system_cpd_set() - report the result of the captive portal detection

View file

@ -70,11 +70,17 @@ lws_getaddrinfo46(struct lws *wsi, const char *ads, struct addrinfo **result)
#endif #endif
#if defined(EAI_FAIL) #if defined(EAI_FAIL)
|| n == EAI_FAIL || n == EAI_FAIL
#endif
#if defined(EAI_AGAIN)
|| n == EAI_AGAIN
#endif #endif
) { ) {
#if defined(LWS_WITH_SECURE_STREAMS)
#endif
wsi->dns_reachability = 1; wsi->dns_reachability = 1;
lwsl_notice("%s: asking to recheck CPD\n", __func__); lwsl_notice("%s: asking to recheck CPD in 1ms\n", __func__);
lws_system_cpd_start(wsi->a.context); lws_system_cpd_start_defer(wsi->a.context, LWS_US_PER_MS);
} }
lwsl_info("%s: getaddrinfo '%s' says %d\n", __func__, ads, n); lwsl_info("%s: getaddrinfo '%s' says %d\n", __func__, ads, n);

View file

@ -1401,6 +1401,22 @@ lws_system_cpd_start(struct lws_context *cx)
#endif #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" }; static const char *cname[] = { "Unknown", "OK", "Captive", "No internet" };
void void

View file

@ -397,6 +397,7 @@ struct lws_context {
#if defined(LWS_WITH_SECURE_STREAMS) #if defined(LWS_WITH_SECURE_STREAMS)
struct lws_ss_handle *ss_cpd; struct lws_ss_handle *ss_cpd;
#endif #endif
lws_sorted_usec_list_t sul_cpd_defer;
#if defined(LWS_WITH_NETWORK) #if defined(LWS_WITH_NETWORK)
struct lws_context_per_thread pt[LWS_MAX_SMP]; struct lws_context_per_thread pt[LWS_MAX_SMP];