My app (C++, Windows) is communicating with an external device. If the device doesn't answer after certain period of time, I want to reset a status variable.
My initial approach would be
auto timer = boost::asio::deadline_timer(io_svc);
timer.expires_from_now(boost::posix_time::seconds(10));
timer.async_wait(boost::bind(&Class::CurrRequestTimeout, this, boost::asio::placeholders::error));
io_svc.poll();
and the timeout function
void Class::CurrRequestTimeout(const boost::system::error_code & ec)
{
if (ec)
{
// this timeout was canceled
return;
}
ResetStatusVariable();
}
This should be non-blocking, that's why I selected poll() instead of run() (seen here). However, with poll() the timeout method is never called. With run() it works just fine, but this blocks the execution.