#include "navmon.hh" #include #include #include #include #include #include "fmt/format.h" #include "fmt/printf.h" #include #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 "<& str) { char tmp[5]; string ret; ret.reserve((int)(str.size()*2.2)); for(string::size_type n=0;n formats({"%Y-%m-%d %H:%M", "%Y-%m-%d %H:%M:%S", "%Y%m%d %H%M", "%H:%M", "%H%M"}); for(const auto& f : formats) { struct tm tm; memset(&tm, 0, sizeof(tm)); localtime_r(&now, &tm); tm.tm_isdst = -1; tm.tm_sec = 0; char* res = strptime(&in[0], f.c_str(), &tm); if(res && !*res) { // cerr<<"Matched on "<