c++ - 提升 asio io_service 与 io_context
问题描述
我正在使用带有 c++ 的 boost asio 库。我发现 io_service 和 io_context 有相似之处。例如两者都有方法运行和其他。有人可以详细说明这两个类之间的区别(如用法、概念、结构差异等)
解决方案
你应该使用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_allocator
和boost::asio::associated_executor
,默认查找 组合操作函数对象的 成员get_allocator()
、 get_executor()
、 。T::allocator_type
T::executor_type
这不是一个完整的列表。
这些更改与Networking TS 兼容性有关。
似乎已在Boost 1.66中添加。
推荐阅读
- elasticsearch - 用于脚本标签的 Elasticsearch JAVA API
- charts - 如何根据表格中的聚合日期值在 Google Data Studio 中创建饼图?
- c++ - 显式专业化必须在其首次使用之前
- sql - Postgresql > 交叉表查询 > 需要输入
- android - Kotlin - 使用自定义 URL 方案验证 URL
- php - 数据插入失败,但更新工作在 mysql - php 使用 $stmt
- youtube-analytics-api - 如何从 Youtube API 的频道报告中获取顶级国家/地区
- java - 如何修复 UnsatisfiedLinkError: dalvik.system.PathClassLoader?
- php - 如何从 Mysql 表中创建按天分组的连续日期图表?
- neo4j - 通过 Cypher 导入 json 文件时出现 Neo4j 错误