Open wjwwood opened 10 years ago
wouldn't it be better to use gettimeofday() instead fo clock_get_time()? I believe this is portable for both osx as linux. It is already used in qeo-c/qeo-c-core/src/core.c.
Certainly you could use gettimeofday()
which should be portable, but it has a lower resolution timestruct
(us vs ns) so I wanted to emulate the existing code as closely as possible.
I see, good point. However the precision of that part is not really critical. It's used to poll for upnp changes every once and a while, so some drag doesn't harm.
I guess the other big difference between the two is that with clock_get_time()
can be made to be monotonic, where as gettimeofday()
can time travel backwards or forwards if the system time is changed during run time. I don't know if that makes a difference.
The monotonicity is indeed important in this piece of code. So I would go with the clock_get_time implementation. However, could we also put it in ./tinq-core/dds/src/co/sys.c:800? This is the code dds uses to simulate clock_gettime on OSX. It would also benefit from a monotonic clock with better resolution....
@wjwwood: would you be willing to cput your code there as well and update your pull request? @mouse256: maybe we should simply use the dds implementation, or we could try to use DDS_Timer iso the timers that the forwarder is currently using?
@brunodebus Sure, I'll look at doing that today.
Ok, so I moved the code, but it is a bit messy and I don't know how you want it organized. I'll comment on the changes inline in a few places.
I was building on my macbook and ran into a few issues in addition to needing to install a few packages from Homebrew. So I made a pull request with my changes in case you guys want to incorperate them. I have not tested these changes on Linux.
Also I had to install these things from Homebrew before building:
coreutils
findutils
gnu-tar