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