This is Unofficial EPICS BASE Doxygen Site
osdTime.h File Reference
#include <sys/times.h>
#include <tickLib.h>
#include <sysLib.h>
+ Include dependency graph for osdTime.h:

Go to the source code of this file.

Macros

#define osdTickRateGet   sysClkRateGet
 
#define osdTickGet   tickGet
 

Functions

void osdNTPInit (void)
 
int osdNTPGet (struct timespec *)
 
void osdNTPReport (void)
 

Macro Definition Documentation

#define osdTickGet   tickGet

Definition at line 28 of file osdTime.h.

#define osdTickRateGet   sysClkRateGet

Definition at line 27 of file osdTime.h.

Function Documentation

int osdNTPGet ( struct timespec )

Definition at line 45 of file osdTime.cpp.

46 {
47  static unsigned bequiet;
48  ssize_t ret;
49 
50  if (ntpSocket < 0)
51  return -1;
52 
53  /* rtems_bsdnet_get_ntp() will send an NTP request, then
54  * call recvfrom() exactly once to process the expected reply.
55  * Any leftovers in the socket buffer (ie. duplicates of
56  * previous replies) will cause problems.
57  * So flush out the socket buffer first.
58  */
59  do {
60  char junk[16];
61 
62  ret = recvfrom(ntpSocket, junk, sizeof(junk), MSG_DONTWAIT, NULL, NULL);
63  if (ret == -1 && errno == EAGAIN) {
64  break;
65  }
66  else if (ret == -1) {
67  if (!bequiet) {
68  printf("osdNTPGet cleaner error: %s\n", strerror(errno));
69  bequiet = 1;
70  }
71  break;
72  }
73  else {
74  bequiet = 0;
75  }
76  } while (ret > 0);
77 
78  return rtems_bsdnet_get_ntp(ntpSocket, NULL, ts);
79 }
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
int rtems_bsdnet_get_ntp(int, int(*)(), struct timespec *)
void osdNTPInit ( void  )

Definition at line 81 of file osdTime.cpp.

82 {
83  struct sockaddr_in myAddr;
84 
85  ntpSocket = socket (AF_INET, SOCK_DGRAM, 0);
86  if (ntpSocket < 0) {
87  printf("osdNTPInit() Can't create socket: %s\n", strerror (errno));
88  return;
89  }
90  memset (&myAddr, 0, sizeof myAddr);
91  myAddr.sin_family = AF_INET;
92  myAddr.sin_port = htons (0);
93  myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
94  if (bind (ntpSocket, (struct sockaddr *)&myAddr, sizeof myAddr) < 0) {
95  printf("osdNTPInit() Can't bind socket: %s\n", strerror (errno));
96  close (ntpSocket);
97  ntpSocket = -1;
98  }
99 }
#define printf
Definition: epicsStdio.h:41
void osdNTPReport ( void  )

Definition at line 101 of file osdTime.cpp.

102 {
103 }