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

有界缓冲写适配器。 更多...

Public 成员函数

 BufWriter (Writer &writer, std::size_t capacity=8192)
 构造BufWriter对象。
task< expected< void > > flush ()
 提交缓冲中尚未写出的字节。
task< expected< std::size_t > > write (std::span< const char > input)
 将提供的字节写入目标。
task< expected< io_transfer > > write (io_buffer input)
 将提供的字节写入目标。
task< expected< void > > shutdown ()
 结束指定方向的 I/O,或按策略关闭运行时。
std::span< const char > pending_bytes () const noexcept
 查看写缓冲中尚未提交的字节。
std::vector< char > take_pending ()
 取走写缓冲中尚未提交的字节。
Writer & get_ref () noexcept
 访问被适配器借用的底层对象。

详细描述

template<borrowed_async_writer Writer>
class faio::io::BufWriter< Writer >

有界缓冲写适配器。

公共头文件
#include <faio/io/stream.hpp>
注解
析构不执行异步 flush;退出前显式等待 flush 或 shutdown。

构造及析构函数说明

◆ BufWriter()

template<borrowed_async_writer Writer>
faio::io::BufWriter< Writer >::BufWriter ( Writer & writer,
std::size_t capacity = 8192 )
explicit

构造BufWriter对象。

参数
writer借用的异步写入器,必须覆盖组合操作的生命周期。
capacity缓冲区或通道的容量;缓冲适配器和 MPSC 通道要求大于零。 默认值:8192。
返回值
构造函数不返回值。
注解
析构不执行异步 flush;退出前显式等待 flush 或 shutdown。

成员函数说明

◆ flush()

template<borrowed_async_writer Writer>
task< expected< void > > faio::io::BufWriter< Writer >::flush ( )

提交缓冲中尚未写出的字节。

返回
等待后返回 expected<void>。
注解
BufWriter 失败时保留未提交部分;无用户缓冲的流不表示磁盘持久化。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ write() [1/2]

template<borrowed_async_writer Writer>
task< expected< std::size_t > > faio::io::BufWriter< Writer >::write ( std::span< const char > input)

将提供的字节写入目标。

参数
input要写入的只读字节视图;借用负载在操作完成前保持有效且不得并发修改。
返回
等待后返回 expected<size_t>,表示本次实际传输字节数。
注解
允许短写;需要完整写入时使用 write_all。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ write() [2/2]

template<borrowed_async_writer Writer>
task< expected< io_transfer > > faio::io::BufWriter< Writer >::write ( io_buffer input)

将提供的字节写入目标。

参数
input移动传入的拥有型缓冲区;写入使用有效范围,读取使用可写容量,完成后通过 io_transfer 归还。
返回
等待后返回 expected<io_transfer>;buffer 归还拥有的缓冲,bytes 为本次传输量。
注解
允许短写;需要完整写入时使用 write_all。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ shutdown()

template<borrowed_async_writer Writer>
task< expected< void > > faio::io::BufWriter< Writer >::shutdown ( )

结束指定方向的 I/O,或按策略关闭运行时。

返回
I/O 对象等待后得到 expected<void>;runtime::shutdown 为同步无返回值。
错误与异常
返回 expected 的重载以 error() 报告失败;先检查成功状态再读取值。任务中的异常沿等待链传播。

◆ pending_bytes()

template<borrowed_async_writer Writer>
std::span< const char > faio::io::BufWriter< Writer >::pending_bytes ( ) const
noexcept

查看写缓冲中尚未提交的字节。

返回
返回借用的只读 span。

◆ take_pending()

template<borrowed_async_writer Writer>
std::vector< char > faio::io::BufWriter< Writer >::take_pending ( )

取走写缓冲中尚未提交的字节。

返回
返回 vector<char>,适配器的待写缓冲随后清空。

◆ get_ref()

template<borrowed_async_writer Writer>
Writer & faio::io::BufWriter< Writer >::get_ref ( )
noexcept

访问被适配器借用的底层对象。

返回
返回 Reader& 或 Writer&。
注解
不要绕过适配器中未消费或未提交的内容。