启动一个异步操作,将所有提供的写入数据流。
template< typename AsyncWriteStream, typename Allocator, typename WriteToken = default_completion_token_t<typename AsyncWriteStream::executor_type>> DEDUCED async_write( AsyncWriteStream & s, basic_streambuf< Allocator > & b, WriteToken && token = default_completion_token_t< typename AsyncWriteStream::executor_type >(), constraint_t< !is_completion_condition< decay_t< WriteToken > >::value > = 0);
此函数用于将一定数量的字节数据异步写入流。它是 异步操作 的启动函数,并且始终立即返回。异步操作将一直继续,直到满足以下条件之一:
basic_streambuf
中的所有数据。此操作通过零次或多次调用流的 async_write_some 函数来实现,并被称为 组合操作。程序必须确保在操作完成之前,流不执行任何其他写操作(如 async_write、流的 async_write_some 函数,或任何其他执行写的组合操作)。
要写入数据的流。类型必须支持 AsyncWriteStream 概念。
一个 basic_streambuf
对象,数据将从中写入。streambuf 的所有权由调用者保留,调用者必须确保在调用完成处理程序之前它保持有效。
将用于生成完成处理程序的 完成令牌,将在写入完成后调用。潜在的完成令牌包括 use_future
、use_awaitable
、yield_context
,或具有正确完成签名的函数对象。完成处理程序的函数签名必须为:
void handler( // Result of operation. const boost::system::error_code& error, // Number of bytes written from the buffers. If an error // occurred, this will be less than the sum of the buffer sizes. std::size_t bytes_transferred );
无论异步操作是否立即完成,都不会在此函数内调用完成处理程序。在立即完成的情况下,将以等同于使用 async_immediate
的方式调用处理程序。
void(boost::system::error_code, std::size_t)
此异步操作支持以下 cancellation_type
值的取消
cancellation_type::terminal
cancellation_type::partial
如果它们也由 AsyncWriteStream
类型的 async_write_some
操作支持。