#include "navmon.hh" #include #include #include #include #include #include "fmt/format.h" #include "fmt/printf.h" #include #include #include using namespace std; using Clock = std::chrono::steady_clock; static double passedMsec(const Clock::time_point& then, const Clock::time_point& now) { return std::chrono::duration_cast(now - then).count()/1000.0; } static double passedMsec(const Clock::time_point& then) { return passedMsec(then, Clock::now()); } size_t readn2Timeout(int fd, void* buffer, size_t len, double* timeout) { size_t pos=0; ssize_t res; /* The plan. Calculate the 'end time', which is now + timeout At beginning of loop, calculate how many milliseconds this is in the future If <= 0, set remaining *timeout to 0, throw timeout exception Then wait that many milliseconds, if timeout, set remaining *timeout to zero, throw timeout Otherwise only adjust *timeout */ auto limit = Clock::now(); if(timeout) { // cerr<<"Called with timeout "<<*timeout<<", "<<(*timeout*1000)<<"msec for "<