启动一个异步操作,在指定的偏移量写入一定量的数据。
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 操作也支持它们。