mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
ntpclient: add plat-specific init with env var LWS_NTP_SERVER able to set it on unix and windows
Trying to use a remote pool is very variable with CI, the builder can force a local ntpd this way cleanly. When enabled all the test apps use ntpclient, so this lets us tell them all to go to the local ntpd in one hit.
This commit is contained in:
parent
ee40b52c62
commit
c95706a17f
6 changed files with 77 additions and 0 deletions
|
@ -710,6 +710,9 @@ int
|
|||
lws_plat_user_colon_group_to_ids(const char *u_colon_g, uid_t *puid, gid_t *pgid);
|
||||
#endif
|
||||
|
||||
int
|
||||
lws_plat_ntpclient_config(struct lws_context *context);
|
||||
|
||||
int
|
||||
lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len);
|
||||
|
||||
|
|
|
@ -40,3 +40,20 @@ lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46)
|
|||
|
||||
return s;
|
||||
}
|
||||
|
||||
int
|
||||
lws_plat_ntpclient_config(struct lws_context *context)
|
||||
{
|
||||
#if 0
|
||||
char *ntpsrv = getenv("LWS_NTP_SERVER");
|
||||
|
||||
if (ntpsrv && strlen(ntpsrv) < 64) {
|
||||
lws_system_blob_heap_append(lws_system_get_blob(context,
|
||||
LWS_SYSBLOB_TYPE_NTP_SERVER, 0),
|
||||
(const uint8_t *)ntpsrv,
|
||||
strlen(ntpsrv));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -235,3 +235,20 @@ lws_plat_recommended_rsa_bits(void)
|
|||
{
|
||||
return 4096;
|
||||
}
|
||||
|
||||
int
|
||||
lws_plat_ntpclient_config(struct lws_context *context)
|
||||
{
|
||||
#if 0
|
||||
char *ntpsrv = getenv("LWS_NTP_SERVER");
|
||||
|
||||
if (ntpsrv && strlen(ntpsrv) < 64) {
|
||||
lws_system_blob_heap_append(lws_system_get_blob(context,
|
||||
LWS_SYSBLOB_TYPE_NTP_SERVER, 0),
|
||||
(const uint8_t *)ntpsrv,
|
||||
strlen(ntpsrv));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -88,3 +88,24 @@ lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46)
|
|||
|
||||
return LADNS_CONF_SERVER_UNKNOWN;
|
||||
}
|
||||
|
||||
/*
|
||||
* Platform-specific ntpclient server configuration
|
||||
*/
|
||||
|
||||
int
|
||||
lws_plat_ntpclient_config(struct lws_context *context)
|
||||
{
|
||||
#if defined(LWS_HAVE_GETENV)
|
||||
char *ntpsrv = getenv("LWS_NTP_SERVER");
|
||||
|
||||
if (ntpsrv && strlen(ntpsrv) < 64) {
|
||||
lws_system_blob_direct_set(lws_system_get_blob(context,
|
||||
LWS_SYSBLOB_TYPE_NTP_SERVER, 0),
|
||||
(const uint8_t *)ntpsrv,
|
||||
strlen(ntpsrv));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -48,3 +48,19 @@ lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46)
|
|||
LADNS_CONF_SERVER_UNKNOWN;
|
||||
}
|
||||
|
||||
int
|
||||
lws_plat_ntpclient_config(struct lws_context *context)
|
||||
{
|
||||
#if defined(LWS_HAVE_GETENV)
|
||||
char *ntpsrv = getenv("LWS_NTP_SERVER");
|
||||
|
||||
if (ntpsrv && strlen(ntpsrv) < 64) {
|
||||
lws_system_blob_heap_append(lws_system_get_blob(context,
|
||||
LWS_SYSBLOB_TYPE_NTP_SERVER, 0),
|
||||
(const uint8_t *)ntpsrv,
|
||||
strlen(ntpsrv));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -159,10 +159,13 @@ callback_ntpc(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
|||
lws_state_reg_notifier(&wsi->context->mgr_system, &v->notify_link);
|
||||
|
||||
v->ntp_server_ads = "pool.ntp.org";
|
||||
lws_plat_ntpclient_config(v->context);
|
||||
lws_system_blob_get_single_ptr(lws_system_get_blob(
|
||||
v->context, LWS_SYSBLOB_TYPE_NTP_SERVER, 0),
|
||||
(const uint8_t **)&v->ntp_server_ads);
|
||||
|
||||
lwsl_info("%s: using ntp server %s\n", __func__, v->ntp_server_ads);
|
||||
|
||||
lws_ntpc_retry_conn(&v->sul_conn);
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue