我的目标是让我的项目使用" asio"没有Boost的库,但使用C ++ 11。示例是将此server代码转换为使用超时。
这是我做的:
boost::bind
- > std::bind
,_1
- > std::placeholders::_1
boost::asio::xxx
- > asio::xxx
boost::system::error_code
- > asio::error_code
现在,deadline_timer还有12个错误:
deadline_timer input_deadline_;
input_deadline_.expires_at(boost::posix_time::pos_infin);
...
void check_deadline(deadline_timer* deadline)
{
...
if (deadline->expires_at() <= deadline_timer::traits_type::now())
使用的代码是什么?我正在使用GCC 4.9.1 / 2,并且新下载了asio库1.10.6。
答案 0 :(得分:6)
您可以改用high_resolution_timer
,它在C ++ 11编译器上使用std::chrono
:
#if defined(GENERATING_DOCUMENTATION)
/// Typedef for a timer based on the high resolution clock.
/**
* This typedef uses the C++11 @c <chrono> standard library facility, if
* available. Otherwise, it may use the Boost.Chrono library. To explicitly
* utilise Boost.Chrono, use the basic_waitable_timer template directly:
* @code
* typedef basic_waitable_timer<boost::chrono::high_resolution_clock> timer;
* @endcode
*/
typedef basic_waitable_timer<
chrono::high_resolution_clock>
high_resolution_timer;
#elif defined(ASIO_HAS_STD_CHRONO)
typedef basic_waitable_timer<
std::chrono::high_resolution_clock>
high_resolution_timer;
#elif defined(ASIO_HAS_BOOST_CHRONO)
typedef basic_waitable_timer<
boost::chrono::high_resolution_clock>
high_resolution_timer;
#endif
} // namespace asio