Boost C++ 库

……这是世界上评价最高、设计最精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

async_read_at (4 个重载中的第 3 个) - Boost C++ 函数库
PrevUpHomeNext

启动一个异步操作,以指定的偏移量读取一定量的数据。

template<
    typename AsyncRandomAccessReadDevice,
    typename Allocator,
    typename ReadToken = default_completion_token_t<        typename AsyncRandomAccessReadDevice::executor_type>>
DEDUCED async_read_at(
    AsyncRandomAccessReadDevice & d,
    uint64_t offset,
    basic_streambuf< Allocator > & b,
    ReadToken && token = default_completion_token_t< typename AsyncRandomAccessReadDevice::executor_type >(),
    constraint_t< !is_completion_condition< ReadToken >::value >  = 0);

此函数用于从随机访问设备上的指定偏移量异步读取一定数量的字节。它是一个 异步操作 的发起函数,并且始终立即返回。异步操作将一直进行,直到满足以下任一条件为止。

  • 发生错误。

此操作通过零次或多次调用设备的 async_read_some_at 函数来实现。

参数

d

要从中读取数据的设备。类型必须支持 AsyncRandomAccessReadDevice 概念。

offset

将读取数据的偏移量。

b

一个 basic_streambuf 对象,数据将读取到其中。streambuf 的所有权由调用者保留,调用者必须保证在调用完成处理程序之前 streambuf 保持有效。

标记

用于生成完成处理程序的 完成令牌,在读取完成后将被调用。潜在的完成令牌包括 use_futureuse_awaitableyield_context,或者一个具有正确完成签名的函数对象。完成处理程序的函数签名必须是:

void handler(
  // Result of operation.
  const boost::system::error_code& error,

  // Number of bytes copied into the buffers. If an error
  // occurred, this will be the number of bytes successfully
  // transferred prior to the error.
  std::size_t bytes_transferred
);

无论异步操作是否立即完成,完成处理程序都不会在此函数内部调用。在立即完成时,处理程序的调用将以等同于使用 async_immediate 的方式执行。

完成签名
void(boost::system::error_code, std::size_t)
备注

此重载等同于调用

boost::asio::async_read_at(
   d, 42, b,
   boost::asio::transfer_all(),
   handler);
按操作取消

此异步操作支持以下 cancellation_type 值的取消

  • cancellation_type::terminal
  • cancellation_type::partial

如果 AsyncRandomAccessReadDevice 类型的 async_read_some_at 操作也支持它们。


PrevUpHomeNext