启动异步操作,在指定偏移量处写入一定量的数据。
template< typename AsyncRandomAccessWriteDevice, typename Allocator, typename CompletionCondition, typename WriteToken = default_completion_token_t< typename AsyncRandomAccessWriteDevice::executor_type>> DEDUCED async_write_at( AsyncRandomAccessWriteDevice & d, uint64_t offset, basic_streambuf< Allocator > & b, CompletionCondition completion_condition, WriteToken && token = default_completion_token_t< typename AsyncRandomAccessWriteDevice::executor_type >(), constraint_t< is_completion_condition< CompletionCondition >::value > = 0);
此函数用于将指定数量的字节数据异步写入到随机访问设备上的指定偏移量。它是一个 异步操作 的启动函数,并且总是立即返回。异步操作将一直进行,直到以下任一条件成立为止:
basic_streambuf
中的所有数据。此操作是通过零次或多次调用设备的 async_write_some_at 函数来实现的,被称为 复合操作。程序必须确保设备在完成此操作之前不执行 重叠 的写操作(例如 async_write_at、设备的 async_write_some_at 函数,或任何执行写的其他复合操作)。如果操作由它们的偏移量和要写入的字节数定义的区域相交,则这些操作就是重叠的。
要写入_数据的设备_。类型必须支持 AsyncRandomAccessWriteDevice 概念。
将要写入_数据的偏移量_。
一个 basic_streambuf
对象,数据将从中写入。streambuf 的所有权由调用者保留,调用者必须保证在调用完成处理程序之前它保持有效。
用于确定写入操作是否完成的函数对象。函数对象的签名必须是:
std::size_t completion_condition( // Result of latest async_write_some_at operation. const boost::system::error_code& error, // Number of bytes transferred so far. std::size_t bytes_transferred );
返回值为 0 表示写操作已完成。非零返回值表示下次调用设备的 async_write_some_at 函数时要写入的最大字节数。
将用于生成完成处理程序的 完成令牌,该处理程序将在写入完成时被调用。可能的完成令牌包括 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
如果它们也由 AsyncRandomAccessWriteDevice
类型的 async_write_some_at 操作支持。