提升 asio io_service 与 io_context

Vla*_*iev 17 c++ boost boost-asio

我正在使用带有 C++ 的 boost asio 库。我发现 io_service 和 io_context 有相似之处。例如,两者都有方法运行和其他方法。有人可以请详细说明这两个类之间的差异(如用法、概念思想、结构差异等)

rus*_*tyx 18

你应该使用io_context,它取代了io_service.

根据提升问题#110

io_service已弃用。是的,您应该使用io_context. 请注意,“旧” API 也已弃用(例如io_service.post(),您应该使用post(io_context, handler))。

. . .

io_service-> io_context
io_service.post()-> io_context.get_executor().post()
io_service.dispatch()->io_context.get_executor().dispatch()

io_service::strand -> strand<io_context::executor_type>

也有变为由操作定制钩-只有2现在-boost::asio::associated_allocatorboost::asio::associated_executor,缺省情况寻找 get_allocator(),克et_executor()T::allocator_typeT::executor_type 所构成的操作功能对象的成员。

这不是一个完整的列表。

这些更改与Networking TS 兼容性有关

似乎已在Boost 1.66 中添加。

  • 一些文档似乎已经过时,如“1.71”的示例,他们仍在使用“io_service”:https://www.boost.org/doc/libs/1_71_0/doc/html/boost_process/tutorial.html (2认同)