[英]Boost asio io_service vs io_context
I am using boost asio library with c++.我正在使用带有 C++ 的 boost asio 库。 I found that io_service and io_context have similarities.
我发现 io_service 和 io_context 有相似之处。 for example both have method run and others.
例如,两者都有方法运行和其他方法。 Could someone please detail differences between these two classes( like usage, conceptual idea, structural difference et.c)
有人可以请详细说明这两个类之间的差异(如用法、概念思想、结构差异等)
You should use io_context
, it replaces io_service
.您应该使用
io_context
,它取代了io_service
。
According to boost issue #110 :根据提升问题#110 :
io_service
is deprecated.io_service
已弃用。 Yes, you should useio_context
.是的,您应该使用
io_context
。 Beware that the "old" API is deprecated as well (egio_service.post()
, you should usepost(io_context, handler)
).请注意,“旧”API 也已弃用(例如
io_service.post()
,您应该使用post(io_context, handler)
)。.
. .
. .
.
io_service
->io_context
io_service
->io_context
io_service.post()
->io_context.get_executor().post()
io_service.post()
->io_context.get_executor().post()
io_service.dispatch()
->io_context.get_executor().dispatch()
io_service.dispatch()
->io_context.get_executor().dispatch()
io_service::strand
->strand<io_context::executor_type>
io_service::strand
->strand<io_context::executor_type>
there were also changes to composed operation customization hooks - there are only 2 now -
boost::asio::associated_allocator
andboost::asio::associated_executor
, which default to looking forget_allocator()
, get_executor()
,T::allocator_type
,T::executor_type
members of the composed operation function object.组合操作自定义钩子也发生了变化——现在只有 2 个——
boost::asio::associated_allocator
和boost::asio::associated_executor
,它们默认寻找get_allocator()
,et_executor()
,T::allocator_type
,T::executor_type
组合操作函数对象的成员。This is not a complete list.
这不是一个完整的列表。
These changes are related to Networking TS compatibility .这些更改与Networking TS 兼容性有关。
Seems to have been added in Boost 1.66 .似乎已在Boost 1.66 中添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.