【问题标题】:Boost asio io_service vs io_context提升 asio io_service 与 io_context
【发布时间】:2020-05-02 08:05:02
【问题描述】:

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

【问题讨论】:

    标签: c++ boost boost-asio


    【解决方案1】:

    你应该使用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(), get_executor(), T::allocator_type, T::executor_type 组合操作函数对象的成员。

    这不是一个完整的列表。

    这些更改与Networking TS compatibility 有关。

    好像已经在Boost 1.66中添加了。

    【讨论】:

    猜你喜欢
    • 2011-01-20
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 2021-12-23
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多