You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
660 B
44 lines
660 B
5 years ago
|
#include "webfuse/utils/timeout_watcher.hpp"
|
||
5 years ago
|
#include <stdexcept>
|
||
|
|
||
|
using std::chrono::milliseconds;
|
||
|
using std::chrono::duration_cast;
|
||
|
using std::chrono::steady_clock;
|
||
|
|
||
|
namespace
|
||
|
{
|
||
|
milliseconds now()
|
||
|
{
|
||
|
return duration_cast<milliseconds>(steady_clock::now().time_since_epoch());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
namespace webfuse_test
|
||
|
{
|
||
|
|
||
|
TimeoutWatcher::TimeoutWatcher(milliseconds timeout)
|
||
|
: startedAt(now())
|
||
|
, timeout_(timeout)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
TimeoutWatcher::~TimeoutWatcher()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
bool TimeoutWatcher::isTimeout()
|
||
|
{
|
||
|
return (now() - startedAt) > timeout_;
|
||
|
}
|
||
|
|
||
|
void TimeoutWatcher::check()
|
||
|
{
|
||
|
if (isTimeout())
|
||
|
{
|
||
|
throw std::runtime_error("timeout");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|