Merge fixes from 3.15 branch, to revno 12733
This commit is contained in:
@@ -10,6 +10,9 @@
|
||||
*
|
||||
* Author: W. Eric Norum
|
||||
*/
|
||||
#define __BSD_VISIBLE 1
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <epicsStdio.h>
|
||||
#include <rtems.h>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user