diff --git a/acquire.c b/acquire.c index 048f0a5..87df353 100644 --- a/acquire.c +++ b/acquire.c @@ -436,7 +436,6 @@ read_from_socket(void *anything) IPAddr remote_ip; int i, ok; struct timeval now; - double local_time_err; SourceRecord *src; flags = 0; @@ -444,7 +443,7 @@ read_from_socket(void *anything) his_addr_len = sizeof(his_addr); /* Get timestamp */ - LCL_ReadCookedTime(&now, &local_time_err); + SCH_GetFileReadyTime(&now); sock_fd = (long)anything; status = recvfrom (sock_fd, (char *)&msg, message_length, flags, diff --git a/ntp_io.c b/ntp_io.c index 98edc69..1c897bb 100644 --- a/ntp_io.c +++ b/ntp_io.c @@ -275,7 +275,6 @@ read_from_socket(void *anything) unsigned int flags = 0; struct timeval now; NTP_Remote_Address remote_addr; - double local_clock_err; char cmsgbuf[256]; struct msghdr msg; struct iovec iov; @@ -283,7 +282,7 @@ read_from_socket(void *anything) assert(initialised); - LCL_ReadCookedTime(&now, &local_clock_err); + SCH_GetFileReadyTime(&now); iov.iov_base = message.arbitrary; iov.iov_len = sizeof(message); diff --git a/rtc_linux.c b/rtc_linux.c index 0009817..dfdad99 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -872,7 +872,6 @@ read_from_device(void *any) struct rtc_time rtc_raw; struct tm rtc_tm; time_t rtc_t; - double read_err; int error = 0; status = read(fd, &data, sizeof(data)); @@ -905,7 +904,7 @@ read_from_device(void *any) /* Read RTC time, sandwiched between two polls of the system clock so we can bound any error. */ - LCL_ReadCookedTime(&sys_time, &read_err); + SCH_GetFileReadyTime(&sys_time); status = ioctl(fd, RTC_RD_TIME, &rtc_raw); if (status < 0) { diff --git a/sched.c b/sched.c index 3e44a8d..e20054a 100644 --- a/sched.c +++ b/sched.c @@ -71,6 +71,9 @@ typedef struct { static FileHandlerEntry file_handlers[FD_SET_SIZE]; +/* Last timestamp when a file descriptor became readable */ +static struct timeval last_fdready; + /* ================================================== */ /* Variables to handler the timer queue */ @@ -225,6 +228,14 @@ SCH_RemoveInputFileHandler(int fd) /* ================================================== */ +void +SCH_GetFileReadyTime(struct timeval *tv) +{ + *tv = last_fdready; +} + +/* ================================================== */ + #define TQE_ALLOC_QUANTUM 32 static TimerQueueEntry * @@ -514,6 +525,7 @@ SCH_MainLoop(void) int status; struct timeval tv, *ptv; struct timeval now; + double err; if (!initialised) { CROAK("Should be initialised"); @@ -551,6 +563,7 @@ SCH_MainLoop(void) } status = select(one_highest_fd, &rd, NULL, NULL, ptv); + LCL_ReadCookedTime(&last_fdready, &err); if (status < 0) { if (!need_to_exit) diff --git a/sched.h b/sched.h index 4e4d98d..0aea7ff 100644 --- a/sched.h +++ b/sched.h @@ -60,6 +60,10 @@ extern void SCH_AddInputFileHandler ); extern void SCH_RemoveInputFileHandler(int fd); +/* Get the time (cooked) when file descriptor became ready, intended for use + in file handlers */ +extern void SCH_GetFileReadyTime(struct timeval *tv); + /* This queues a timeout to elapse at a given (raw) local time */ extern SCH_TimeoutID SCH_AddTimeout(struct timeval *tv, SCH_TimeoutHandler, SCH_ArbitraryArgument);