From 768993fb156f1365167ecab2859bd1df4a85fb7a Mon Sep 17 00:00:00 2001 From: zhanghongyu Date: Fri, 2 Jun 2023 19:08:09 +0800 Subject: [PATCH] ntpclient: change sendto/recv timeout to Kconfig Change the timeout period of ntpclient to configurable to reduce the impact The NTP packet is lost during the first TLS connection after the board is started. Signed-off-by: zhanghongyu --- netutils/ntpclient/Kconfig | 4 ++++ netutils/ntpclient/ntpclient.c | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/netutils/ntpclient/Kconfig b/netutils/ntpclient/Kconfig index 1f0a33c57..c894aea39 100644 --- a/netutils/ntpclient/Kconfig +++ b/netutils/ntpclient/Kconfig @@ -66,6 +66,10 @@ config NETUTILS_NTPCLIENT_SIGWAKEUP int "NTP client wakeup signal number" default 18 +config NETUTILS_NTPCLIENT_TIMEOUT_MS + int "NTP client timeout of send and recv" + default 5000 + config NETUTILS_NTPCLIENT_WITH_AUTH bool "NTP client with authentication" default n diff --git a/netutils/ntpclient/ntpclient.c b/netutils/ntpclient/ntpclient.c index ed18be460..7374c00a2 100644 --- a/netutils/ntpclient/ntpclient.c +++ b/netutils/ntpclient/ntpclient.c @@ -875,8 +875,8 @@ static int ntpc_create_dgram_socket(int domain) /* Setup a send timeout on the socket */ - tv.tv_sec = 5; - tv.tv_usec = 0; + tv.tv_sec = CONFIG_NETUTILS_NTPCLIENT_TIMEOUT_MS / 1000; + tv.tv_usec = CONFIG_NETUTILS_NTPCLIENT_TIMEOUT_MS % 1000; ret = setsockopt(sd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); if (ret < 0) @@ -888,9 +888,6 @@ static int ntpc_create_dgram_socket(int domain) /* Setup a receive timeout on the socket */ - tv.tv_sec = 5; - tv.tv_usec = 0; - ret = setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); if (ret < 0) {