gpt4 book ai didi

c++ - Boost asio io_service 与 io_context

转载 作者:行者123 更新时间:2023-12-01 19:36:54 28 4
gpt4 key购买 nike

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

最佳答案

您应该使用io_context ,它取代 io_service .

根据boost问题#110 :

io_service is deprecated. Yes, you should use io_context. Beware that the "old" API is deprecated as well (e.g. io_service.post(), you should use 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>

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_typemembers of the composed operation function object.

This is not a complete list.

这些更改与 Networking TS compatibility 相关.

似乎已添加到 Boost 1.66 .

关于c++ - Boost asio io_service 与 io_context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59753391/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com