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 <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2023-06-02 19:08:09 +08:00 committed by Xiang Xiao
parent 216df60208
commit 768993fb15
2 changed files with 6 additions and 5 deletions

View File

@ -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

View File

@ -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)
{