NTP Client: All retries; Add initialization in NSH network startup logic.
This commit is contained in:
parent
7a5ceb244e
commit
bfd5ca7cd2
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* netutils/ntpclient/ntpclient.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -59,6 +59,7 @@
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* NTP Time is seconds since 1900. Convert to Unix time which is seconds
|
||||
* since 1970
|
||||
*/
|
||||
@ -69,6 +70,7 @@
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This enumeration describes the state of the NTP daemon */
|
||||
|
||||
enum ntpc_daemon_e
|
||||
@ -105,6 +107,7 @@ static struct ntpc_daemon_s g_ntpc_daemon;
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ntpc_getuint32
|
||||
*
|
||||
@ -293,8 +296,9 @@ static int ntpc_daemon(int argc, char **argv)
|
||||
socklen_t socklen;
|
||||
ssize_t nbytes;
|
||||
int exitcode = EXIT_SUCCESS;
|
||||
int ret;
|
||||
int retry = 0;
|
||||
int sd;
|
||||
int ret;
|
||||
|
||||
/* Indicate that we have started */
|
||||
|
||||
@ -428,6 +432,15 @@ static int ntpc_daemon(int argc, char **argv)
|
||||
int errval = errno;
|
||||
if (errval != EINTR)
|
||||
{
|
||||
/* Allow up to three retries */
|
||||
|
||||
if (++retry < 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Then declare the failure */
|
||||
|
||||
ndbg("ERROR: recvfrom() failed: %d\n", errval);
|
||||
exitcode = EXIT_FAILURE;
|
||||
break;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* apps/nshlib/nsh_netinit.c
|
||||
*
|
||||
* Copyright (C) 2010-2012, 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2010-2012, 2014-2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* This is influenced by similar logic from uIP:
|
||||
@ -72,6 +72,10 @@
|
||||
# include <apps/netutils/dhcpc.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETUTILS_NTPCLIENT
|
||||
# include <apps/netutils/ntpclient.h>
|
||||
#endif
|
||||
|
||||
#include "nsh.h"
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
@ -128,7 +132,6 @@
|
||||
# undef CONFIG_NSH_NETINIT_MONITOR
|
||||
#endif
|
||||
|
||||
|
||||
/* We need a valid IP domain (any domain) to create a socket that we can use
|
||||
* to comunicate with the network device.
|
||||
*/
|
||||
@ -147,10 +150,6 @@
|
||||
#define LONG_TIME_SEC (60*60) /* One hour in seconds */
|
||||
#define SHORT_TIME_SEC (2) /* 2 seconds */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
@ -203,10 +202,6 @@ static const uint16_t g_ipv6_netmask[8] =
|
||||
};
|
||||
#endif /* CONFIG_NET_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF*/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@ -342,6 +337,12 @@ static void nsh_netinit_configure(void)
|
||||
dhcpc_close(handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETUTILS_NTPCLIENT
|
||||
/* Start the NTP client */
|
||||
|
||||
ntpc_start();
|
||||
#endif
|
||||
#endif /* NSH_HAVE_NETDEV */
|
||||
|
||||
nvdbg("Exit\n");
|
||||
|
Loading…
Reference in New Issue
Block a user