如何在没有提升deadline_timer的情况下将boost :: asio代码完全转换为C ++ 11 / asio?

时间:2015-11-29 23:03:29

标签: c++ c++11 boost boost-asio

我的目标是让我的项目使用" asio"没有Boost的库,但使用C ++ 11。示例是将此server代码转换为使用超时。

这是我做的:

  1. boost::bind - > std::bind_1 - > std::placeholders::_1
  2. 大多数boost::asio::xxx - > asio::xxx
  3. boost::system::error_code - > asio::error_code
  4. 现在,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。

1 个答案:

答案 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 &lt;chrono&gt; 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