faio
faio 公共 C++ 接口参考
载入中...
搜索中...
未找到
faio::io::unix::AsyncFd< Owner > 模板类 参考

Unix 非阻塞原生描述符的就绪适配器。 更多...

Public 成员函数

 AsyncFd (Owner owner, io_context context=io_context::current())
 构造AsyncFd对象。
 AsyncFd (AsyncFd &&other) noexcept=default
 构造AsyncFd对象。
auto ready (Interest interest)
 等待所需方向的就绪提示。
auto readable ()
 等待所需方向的就绪提示。
auto writable ()
 等待所需方向的就绪提示。
int native_handle () const noexcept
 借用平台原生句柄。
template<class F>
std::invoke_result_t< F, int > try_io (Interest interest, F &&function)
 执行一次短的非阻塞原生操作。
expected< Owner > into_inner ()
 释放异步包装并归还原生拥有者。
io_context context () const noexcept
 获取对象所属 I/O 上下文。
auto close () noexcept
 关闭句柄或通道端点。
expected< int > into_native () noexcept
 导出原生资源并转移所有权。
expected< void > set_nonblocking (bool enabled) const noexcept
 设置描述符的非阻塞标志。
expected< bool > nonblocking () const noexcept
 查询描述符的非阻塞标志。

静态 Public 成员函数

static expected< AsyncFd > create (io_context context, Owner owner)
 接管原生拥有者并注册非阻塞异步描述符。

详细描述

template<native_fd_owner Owner = OwnedFd>
class faio::io::unix::AsyncFd< Owner >

Unix 非阻塞原生描述符的就绪适配器。

公共头文件
#include <faio/io/native.hpp>
注解
仅在 Unix 提供;普通磁盘文件使用 fs::File。就绪通知不能替代实际非阻塞系统调用。

构造及析构函数说明

◆ AsyncFd() [1/2]

template<native_fd_owner Owner = OwnedFd>
faio::io::unix::AsyncFd< Owner >::AsyncFd ( Owner owner,
io_context context = io_context::current() )
explicit

构造AsyncFd对象。

参数
owner移动传入的原生描述符拥有者,成功后所有权交给包装对象。
context目标 I/O 上下文;省略时使用当前上下文。资源创建后不会因协程迁移而改变归属。 默认值:io_context::current()。
返回值
构造函数不返回值。
注解
仅在 Unix 提供;普通磁盘文件使用 fs::File。就绪通知不能替代实际非阻塞系统调用。

◆ AsyncFd() [2/2]

template<native_fd_owner Owner = OwnedFd>
faio::io::unix::AsyncFd< Owner >::AsyncFd ( AsyncFd< Owner > && other)
defaultnoexcept

构造AsyncFd对象。

参数
other被复制、移动或比较的同类型对象;移动后源对象按该类型约定变空。
返回值
构造函数不返回值。
注解
仅在 Unix 提供;普通磁盘文件使用 fs::File。就绪通知不能替代实际非阻塞系统调用。

成员函数说明

◆ ready()

template<native_fd_owner Owner = OwnedFd>
auto faio::io::unix::AsyncFd< Owner >::ready ( Interest interest)

等待所需方向的就绪提示。

参数
interest需要观察或操作的读写方向集合。
返回
等待后返回 expected<AsyncFdReadyGuard>。
注解
守卫不拥有方向执行权;使用 try_io 执行非阻塞回调。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ readable()

template<native_fd_owner Owner = OwnedFd>
auto faio::io::unix::AsyncFd< Owner >::readable ( )

等待所需方向的就绪提示。

返回
等待后返回 expected<AsyncFdReadyGuard>。
注解
守卫不拥有方向执行权;使用 try_io 执行非阻塞回调。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ writable()

template<native_fd_owner Owner = OwnedFd>
auto faio::io::unix::AsyncFd< Owner >::writable ( )

等待所需方向的就绪提示。

返回
等待后返回 expected<AsyncFdReadyGuard>。
注解
守卫不拥有方向执行权;使用 try_io 执行非阻塞回调。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ native_handle()

template<native_fd_owner Owner = OwnedFd>
int faio::io::unix::AsyncFd< Owner >::native_handle ( ) const
noexcept

借用平台原生句柄。

返回
返回句柄值;调用方不负责关闭。

◆ try_io()

template<native_fd_owner Owner = OwnedFd>
template<class F>
std::invoke_result_t< F, int > faio::io::unix::AsyncFd< Owner >::try_io ( Interest interest,
F && function )

执行一次短的非阻塞原生操作。

参数
interest需要观察或操作的读写方向集合。
function执行所需工作的可调用对象;阻塞任务按值保存,非阻塞 I/O 回调不得阻塞。
返回
返回回调的 expected 结果;暂不可用时由调用方处理。
注解
回调不得阻塞或递归操作同一方向。

◆ into_inner()

template<native_fd_owner Owner = OwnedFd>
expected< Owner > faio::io::unix::AsyncFd< Owner >::into_inner ( )

释放异步包装并归还原生拥有者。

返回
返回 expected<Owner>;在途操作导致导出失败时返回错误。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ create()

template<native_fd_owner Owner = OwnedFd>
expected< AsyncFd > faio::io::unix::AsyncFd< Owner >::create ( io_context context,
Owner owner )
static

接管原生拥有者并注册非阻塞异步描述符。

参数
context目标 I/O 上下文;省略时使用当前上下文。资源创建后不会因协程迁移而改变归属。
owner移动传入的原生描述符拥有者,成功后所有权交给包装对象。
返回
返回 expected<AsyncFd>,失败报告系统错误或 ENOMEM。
注解
不接受普通文件、目录或块设备。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ context()

template<native_fd_owner Owner = OwnedFd>
io_context faio::io::unix::AsyncFd< Owner >::context ( ) const
noexcept

获取对象所属 I/O 上下文。

返回
返回 io_context 引用值,不改变资源的所属上下文。

◆ close()

template<native_fd_owner Owner = OwnedFd>
auto faio::io::unix::AsyncFd< Owner >::close ( )
noexcept

关闭句柄或通道端点。

返回
异步句柄需等待并检查 expected 结果;通道端点 close() 为同步无返回值。
注解
关闭异步资源前应协调在途操作;关闭请求不等于已经完成关闭。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ into_native()

template<native_fd_owner Owner = OwnedFd>
expected< int > faio::io::unix::AsyncFd< Owner >::into_native ( )
noexcept

导出原生资源并转移所有权。

返回
成功返回 expected<owned_native_socket> 或相应的原生拥有者。
注解
在途操作未完成时可能失败,导出后原包装不再拥有资源。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ set_nonblocking()

template<native_fd_owner Owner = OwnedFd>
expected< void > faio::io::unix::AsyncFd< Owner >::set_nonblocking ( bool enabled) const
noexcept

设置描述符的非阻塞标志。

参数
enabledtrue 启用该选项,false 关闭。
返回
返回 expected<void>。
注解
异步就绪操作要求非阻塞模式;不能在在途操作中切换为阻塞模式。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ nonblocking()

template<native_fd_owner Owner = OwnedFd>
expected< bool > faio::io::unix::AsyncFd< Owner >::nonblocking ( ) const
noexcept

查询描述符的非阻塞标志。

返回
返回 expected<bool>。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。