Boost C++ 库

...是全球评价最高、设计最精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

posix::basic_descriptor::async_wait - Boost C++ 函数库
PrevUpHomeNext

异步等待描述符变为可读、可写或出现待处理错误条件。

template<
    typename WaitToken = default_completion_token_t<executor_type>>
DEDUCED async_wait(
    wait_type w,
    WaitToken && token = default_completion_token_t< executor_type >());

此函数用于执行异步等待,以使描述符进入可读、可写或错误条件状态。它是 异步操作 的发起函数,并且始终立即返回。

参数

w

指定所需的描述符状态。

标记

将用于生成完成处理程序的 完成令牌,该处理程序将在等待完成时被调用。可能的完成令牌包括 use_futureuse_awaitableyield_context,或者具有正确完成签名的函数对象。完成处理程序的函数签名必须是

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

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

完成签名
void(boost::system::error_code)
示例
void wait_handler(const boost::system::error_code& error)
{
  if (!error)
  {
    // Wait succeeded.
  }
}

...

boost::asio::posix::stream_descriptor descriptor(my_context);
...
descriptor.async_wait(
    boost::asio::posix::stream_descriptor::wait_read,
    wait_handler);
按操作取消

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

  • cancellation_type::terminal
  • cancellation_type::partial
  • cancellation_type::total

PrevUpHomeNext