NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
file_async类 参考

文件异步I/O管理类 更多...

#include <file_async.hpp>

struct  async_result
 异步操作结果句柄 更多...

Public 类型

using size_type = size_t
 大小类型
using difference_type = ::off_t
 偏移量类型
using aiocb_type = ::aiocb
 异步I/O控制块类型
using native_handle_type = _NEFORCE native_handle_type
 原生文件句柄类型

Public 成员函数

 file_async (native_handle_type handle)
 构造函数
 ~file_async ()
 析构函数
 file_async (file_async &&other) noexcept
 移动构造函数
file_asyncoperator= (file_async &&other) noexcept
 移动赋值运算符
async_result read (string &buffer, size_type size, difference_type offset=-1) const
 提交异步读取操作
async_result write (string data, size_type size, difference_type offset=-1)
 提交异步写入操作
bool wait (async_result &result, uint32_t timeout_ms=numeric_traits< uint32_t >::max())
 等待异步操作完成
void cancel (async_result &result) noexcept
 取消异步操作

详细描述

文件异步I/O管理类

提供对文件句柄的异步读写操作:

  • 非阻塞异步读写
  • 支持超时等待
  • 支持取消操作
  • 线程安全的操作提交
注解
对同一文件的并发操作顺序由操作系统决定。
不持有文件句柄所有权,句柄生命周期由调用方保证。

在文件 file_async.hpp41 行定义.

构造及析构函数说明

◆ file_async() [1/2]

file_async::file_async ( native_handle_type handle)
explicit

构造函数

参数
handle已打开的文件句柄

关联指定的文件句柄。

引用了 handle().

被这些函数引用 file_async(), operator=() , 以及 ~file_async().

◆ ~file_async()

file_async::~file_async ( )

析构函数

取消所有进行中的异步操作并释放资源。

引用了 file_async().

◆ file_async() [2/2]

file_async::file_async ( file_async && other)
noexcept

移动构造函数

参数
other要移动的对象

引用了 file_async().

成员函数说明

◆ cancel()

void file_async::cancel ( async_result & result)
noexcept

取消异步操作

参数
result异步操作结果句柄

尝试取消进行中的异步操作。取消成功后,操作状态会被标记为已完成, error_code会被设置为取消错误码。

◆ operator=()

file_async & file_async::operator= ( file_async && other)
noexcept

移动赋值运算符

参数
other要移动的对象
返回
自身引用

引用了 file_async().

◆ read()

async_result file_async::read ( string & buffer,
size_type size,
difference_type offset = -1 ) const

提交异步读取操作

参数
buffer输出缓冲区(会预先分配空间)
size要读取的字节数
offset文件偏移量,-1表示使用当前文件位置
返回
异步操作结果句柄

从文件读取数据到指定缓冲区。如果size为0,立即返回已完成的结果。 如果offset为-1,使用当前文件指针位置;否则从指定偏移量读取。

引用了 size().

◆ wait()

bool file_async::wait ( async_result & result,
uint32_t timeout_ms = numeric_traitsuint32_t >::max() )

等待异步操作完成

参数
result异步操作结果句柄
timeout_ms超时时间(毫秒),最大值表示无限等待
返回
操作完成返回true,超时或失败返回false

阻塞当前线程直到异步操作完成或超时。 如果操作已完成,立即返回。

引用了 numeric_traits< T, Dummy >::max().

◆ write()

async_result file_async::write ( string data,
size_type size,
difference_type offset = -1 )

提交异步写入操作

参数
data要写入的数据
size要写入的字节数,最大值表示写入全部数据
offset文件偏移量,-1表示使用当前文件位置
返回
异步操作结果句柄

将数据写入文件。数据会被复制到内部存储,调用者可以立即释放。 如果size为最大值,写入整个字符串;否则写入指定长度。

引用了 data() , 以及 size().


该类的文档由以下文件生成: