Skip to content

Commit

Permalink
ntpclient: change sendto/recv timeout to Kconfig
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
zhhyu7 authored and xiaoxiang781216 committed Aug 3, 2023
1 parent 216df60 commit 768993f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions netutils/ntpclient/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions netutils/ntpclient/ntpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down

0 comments on commit 768993f

Please sign in to comment.