Store computed reception time in the message struct so we don't rely on

the message being emitted immediately.

Fix computation of reception time so it's more sensible (the block timestamp
is some time after reception of the _end_ of the block, not the start) - this
means that message-emission times are always later than message-reception
times in SBS output, which is a bit more sensible.

Use clock_gettime in preference to ftime.
This commit is contained in:
Oliver Jowett 2015-02-08 17:46:01 +00:00
parent 1584955080
commit 4e177c2d64
7 changed files with 76 additions and 31 deletions

22
util.c
View file

@ -62,3 +62,25 @@ uint64_t mstime(void)
mst += tv.tv_usec/1000;
return mst;
}
uint64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2)
{
if (t2 < t1) {
// wrapped.
return (~(t1 - t2) + 1) * 1000U / 12U;
} else {
return (t2 - t1) * 1000U / 12U;
}
}
void normalize_timespec(struct timespec *ts)
{
if (ts->tv_nsec > 1000000000) {
ts->tv_sec += ts->tv_nsec / 1000000000;
ts->tv_nsec = ts->tv_nsec % 1000000000;
} else if (ts->tv_nsec < 0) {
long adjust = ts->tv_nsec / 1000000000 + 1;
ts->tv_sec -= adjust;
ts->tv_nsec = (ts->tv_nsec + 1000000000 * adjust) % 1000000000;
}
}