Boost C++ 库

one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

网络 TS 兼容性 - Boost C++ 函数库
PrevUpHomeNext

Boost.Asio 现在提供了“C++ 网络扩展”技术规范中指定接口和功能。除了通过常规的 Boost.Asio 头文件访问外,还可以通过与 TS 中定义的头文件对应的特殊头文件来访问此功能。这些在下表中列出:

网络 TS 头文件

Boost.Asio 头文件

#include <buffer>

#include <boost/asio/ts/buffer.hpp>

#include <executor>

#include <boost/asio/ts/executor.hpp>

#include <internet>

#include <boost/asio/ts/internet.hpp>

#include <io_context>

#include <boost/asio/ts/io_context.hpp>

#include <net>

#include <boost/asio/ts/net.hpp>

#include <netfwd>

#include <boost/asio/ts/netfwd.hpp>

#include <socket>

#include <boost/asio/ts/socket.hpp>

#include <timer>

#include <boost/asio/ts/timer.hpp>

在某些情况下,新的网络 TS 兼容接口取代了旧的 Boost.Asio 设施。在这些情况下,旧接口已被弃用。下表显示了新的网络 TS 接口及其取代的设施:

新接口

旧接口

注意

io_context

io_service

io_service 名称保留为 typedef。

dispatch

io_service::dispatch

free 函数 dispatch 可用于将函数提交到任何 ExecutorExecutionContext

post

io_service::post

free 函数 post 可用于将函数提交到任何 ExecutorExecutionContext

defer

asio_handler_is_continuation hook 返回 true 时,io_service::post

free 函数 defer 可用于将函数提交到任何 ExecutorExecutionContext

io_context::poll

接受 error_code&io_service::poll 重载

不需要 error_code 重载。

io_context::poll_one

接受 error_code&io_service::poll_one 重载

不需要 error_code 重载。

io_context::run

接受 error_code&io_service::run 重载

不需要 error_code 重载。

io_context::run_one

接受 error_code&io_service::run_one 重载

不需要 error_code 重载。

io_context::run_for, io_context::run_until, io_context::run_one_for, and io_context::run_one_until

这些函数增加了运行 io_context 一段时间的功能。

io_context::restart

io_service::reset

io_context 构造函数的 concurrency_hint 参数是 int 类型

io_context 构造函数的 concurrency_hint 参数是 std::size_t 类型

execution_context, execution_context::service, and execution_context::id

io_service, io_service::service, and io_service::id

与服务相关的函数已移至 execution_context 基类。这也可以用作创建自定义执行上下文的基类。

make_service

add_service

strand

io_service::strand

此模板适用于任何有效的执行器,并且本身也是一个有效的执行器。

executor_work_guard and make_work_guard

io_service::work

工作跟踪现在由 Executor 要求覆盖。这些模板适用于任何有效的执行器。

executor_binder and bind_executor

io_service::wrap and io_service::strand::wrap

这些模板适用于任何有效的执行器。

带有 CompletionTokenSignature 模板参数的 async_result

带有单个参数的 handler_typeasync_result

async_result trait 现在是异步操作完成处理程序和返回类型的唯一自定义点。

associated_executor and get_associated_executor

asio_handler_invoke

处理程序调用 hook 已被新的 Executor 要求和相关的执行器 trait 取代。

associated_allocator and get_associated_allocator

asio_handler_allocate and asio_handler_deallocate

处理程序分配 hook 已被标准的 Allocator 要求和相关的分配器 trait 取代。

const_buffer::data and mutable_buffer::data

buffer_cast

const_buffer::size and mutable_buffer::size

针对单个缓冲区的 buffer_size

buffer_size 对于单个缓冲区没有被弃用,因为 const_buffermutable_buffer 现在满足缓冲区序列要求。

const_buffer

const_buffers_1

ConstBufferSequence 要求已修改,因此 const_buffer 现在满足它们。

mutable_buffer

mutable_buffers_1

MutableBufferSequence 要求已修改,因此 mutable_buffer 现在满足它们。

(以及定时器、串口等 I/O 对象的相应成员) basic_socket::get_executor

basic_io_object::get_io_service

使用 get_executor().context() 来获取关联的 io_context

socket_base::max_listen_connections

socket_base::max_connections

socket_base::wait_type, basic_socket::wait, basic_socket::async_wait, basic_socket_acceptor::wait, and basic_socket_acceptor::async_wait

null_buffers

用于响应式 I/O 的操作。

basic_socket_acceptor::accept 返回一个 socket

basic_socket_acceptor::accept 按引用接受一个 socket

使用 move 语义,因此需要 C++11 或更高版本。要将连接接受到不同 io_context 上的 socket 对象,请将目标上下文传递给 accept

basic_socket_acceptor::async_accept 将 socket 传递给处理程序

basic_socket_acceptor::async_accept 按引用接受一个 socket

使用 move 语义,因此需要 C++11 或更高版本。要将连接接受到不同 io_context 上的 socket 对象,请将目标上下文传递给 async_accept

接受范围的 connect 重载

接受单个迭代器的 connect 重载

ip::basic_resolver::resolve 函数现在返回一个范围。当 resolve 函数的结果直接传递给 connect 时,将选择范围重载。

接受范围的 async_connect 重载

接受单个迭代器的 async_connect 重载

ip::basic_resolver::resolve 函数现在返回一个范围。当 resolve 函数的结果直接传递给 async_connect 时,将选择范围重载。

basic_socket_streambuf::duration

basic_socket_streambuf::duration_type

basic_socket_streambuf::time_point

basic_socket_streambuf::time_type

basic_socket_streambuf::expiry

basic_socket_streambuf::expires_at and basic_socket_streambuf::expires_from_now getters

basic_socket_streambuf::expires_after

basic_socket_streambuf::expires_from_now setter

basic_socket_streambuf::error

basic_socket_streambuf::puberror

basic_socket_iostream::duration

basic_socket_iostream::duration_type

basic_socket_iostream::time_point

basic_socket_iostream::time_type

basic_socket_iostream::expiry

basic_socket_iostream::expires_at and basic_socket_iostream::expires_from_now getters

basic_socket_iostream::expires_after

basic_socket_iostream::expires_from_now setter

basic_waitable_timer::cancel

接受 error_code&basic_waitable_timer::cancel 重载

不需要 error_code 重载。

basic_waitable_timer::cancel_one

接受 error_code&basic_waitable_timer::cancel_one 重载

不需要 error_code 重载。

basic_waitable_timer::expires_at setter

接受 error_code&basic_waitable_timer::expires_at setter

不需要 error_code 重载。

basic_waitable_timer::expiry

basic_waitable_timer::expires_at and basic_waitable_timer::expires_from_now getters

basic_waitable_timer::expires_after

basic_waitable_timer::expires_from_now setter

ip::make_address

ip::address::from_string

ip::make_address_v4

ip::address_v4::from_string and ip::address_v6::to_v4

ip::make_address_v6

ip::address_v6::from_string and ip::address_v6::v4_mapped

ip::address::to_string

接受 error_code&ip::address::to_string 重载

不需要 error_code 重载。

ip::address_v4::to_string

接受 error_code&ip::address_v4::to_string 重载

不需要 error_code 重载。

ip::address_v6::to_string

接受 error_code&ip::address_v6::to_string 重载

不需要 error_code 重载。

无替换

ip::address_v6::is_v4_compatible and ip::address_v6::v4_compatible

ip::network_v4

ip::address_v4::broadcast, ip::address_v4::is_class_a, ip::address_v4::is_class_b, ip::address_v4::is_class_c, and ip::address_v4::netmask

network_v4 类增加了使用 CIDR 表示法操作 IPv4 网络地址的功能。

ip::network_v6

network_v6 类增加了使用 CIDR 表示法操作 IPv6 网络地址的功能。

ip::address_v4_iterator and ip::address_v4_range

ip::address_v4_iteratoraddress_v4_range 类增加了迭代所有 IPv4 地址或其子集的功能。

ip::address_v6_iterator and ip::address_v6_range

ip::address_v6_iteratoraddress_v6_range 类增加了迭代所有 IPv6 地址或其子集的功能。

ip::basic_resolver::results_type

ip::basic_resolver::iterator

解析器现在生成范围而不是单个迭代器。

接受主机名和服务作为参数的 ip::basic_resolver::resolve 重载

接受 ip::basic_resolver::queryip::basic_resolver::resolve 重载

ip::basic_resolver::resolve 返回一个范围

ip::basic_resolver::resolve 返回单个迭代器

接受主机名和服务作为参数的 ip::basic_resolver::async_resolve 重载

接受 ip::basic_resolver::queryip::basic_resolver::async_resolve 重载

ip::basic_resolver::async_resolve 向处理程序传递范围

ip::basic_resolver::async_resolve 向处理程序传递单个迭代器


PrevUpHomeNext