From 3f4c6abb318a584203972c2d51c3a9fb55151d45 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 29 Feb 2016 17:07:03 -0600 Subject: [PATCH] Fix for RTEMS NTP sync issue --- documentation/RELEASE_NOTES.html | 10 ++++++++- src/libCom/osi/os/RTEMS/osdTime.cpp | 32 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index 39f737527..33406f2c9 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -13,6 +13,14 @@ +

RTEMS NTP Support Issue

+ +

On RTEMS the NTP Time Provider could in some circumstances get out of sync +with the server because the osdNTPGet() code wasn't clearing its input socket +before sending out a new request. This +(Launchpad bug 1549908) +has now been fixed.

+

CALC engine bitwise operator fixes

The bitwise operators in the CALC engine have been modified to work properly @@ -21,7 +29,7 @@ back-porting some earlier changes from the 3.15 branch, and fixes Launchpad bug #1514520.

-

ipAddrToAsciiAsync.: don't try to join the daemon thread

+

ipAddrToAsciiAsync.: Don't try to join the daemon thread

On process exit, no longer try to stop the worker thread used by to make DNS lookups asynchronous. diff --git a/src/libCom/osi/os/RTEMS/osdTime.cpp b/src/libCom/osi/os/RTEMS/osdTime.cpp index acefa1b09..e71c64a88 100644 --- a/src/libCom/osi/os/RTEMS/osdTime.cpp +++ b/src/libCom/osi/os/RTEMS/osdTime.cpp @@ -10,6 +10,9 @@ * * Author: W. Eric Norum */ +#define __BSD_VISIBLE 1 +#include +#include #include #include @@ -40,8 +43,37 @@ void osdTimeRegister(void) int osdNTPGet(struct timespec *ts) { + static unsigned bequiet; + ssize_t ret; + if (ntpSocket < 0) return -1; + + /* rtems_bsdnet_get_ntp() will send an NTP request, then + * call recvfrom() exactly once to process the expected reply. + * Any leftovers in the socket buffer (ie. duplicates of + * previous replies) will cause problems. + * So flush out the socket buffer first. + */ + do { + char junk[16]; + + ret = recvfrom(ntpSocket, junk, sizeof(junk), MSG_DONTWAIT, NULL, NULL); + if (ret == -1 && errno == EAGAIN) { + break; + } + else if (ret == -1) { + if (!bequiet) { + printf("osdNTPGet cleaner error: %s\n", strerror(errno)); + bequiet = 1; + } + break; + } + else { + bequiet = 0; + } + } while (ret > 0); + return rtems_bsdnet_get_ntp(ntpSocket, NULL, ts); }