增强ASIO io_服务与io_Context
我正在使用带有C++的Boost ASIO库。我发现io_service和io_context有相似之处。例如,两者都有方法运行和其他。谁能详细介绍一下这两个类别之间的区别(如用法、概念、结构差异等)
解决方案
您应该使用io_context,它取代了io_service。
根据Boost问题#110:
io_service已弃用。是的,您应该使用io_context。请注意,";old";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()还对组合操作定制挂钩进行了更改- 现在只有2个-
io_service::strand-&>strand<io_context::executor_type>boost::asio::associated_allocator和boost::asio::associated_executor,默认情况下查找get_allocator(),get_executor(),T::allocator_type,T::executor_type合成的操作函数对象的成员。这不是完整的列表。
这些更改与Networking TS compatibility相关。
似乎已添加到Boost 1.66中。
相关文章