简体   繁体   English

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

[英]How to completely convert boost::asio code to C++11/asio without boost for deadline_timer?

My goal is to have my project to use the " asio " library without Boost, but use C++11. 我的目标是让我的项目使用没有Boost的“ asio ”库,但使用C ++ 11。 The example is to convert this server code to use Timeout. 示例是将此服务器代码转换为使用Timeout。

Here is what I did: 这是我做的:

  1. boost::bind -> std::bind , _1 -> std::placeholders::_1 boost::bind - > std::bind_1 - > std::placeholders::_1
  2. most boost::asio::xxx -> asio::xxx 大多数boost::asio::xxx - > asio::xxx
  3. boost::system::error_code -> asio::error_code boost::system::error_code - > asio::error_code

Now, there is 12 errors left all about deadline_timer : 现在,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())

What is the correct code to use? 什么是正确的代码使用? I am using GCC 4.9.1/2, and newly downloaded asio library 1.10.6. 我正在使用GCC 4.9.1 / 2,并且新下载了asio库1.10.6。

You can use high_resolution_timer instead, which uses std::chrono on C++11 compilers: 您可以使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM