Boost C++ 库

...世界上最受推崇和专业设计的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ 编码标准

PrevUpHomeNext

read_until (24 个重载中的 16 个)

读取数据到 streambuf,直到函数对象指示匹配。

template<
    typename SyncReadStream,
    typename Allocator,
    typename MatchCondition>
std::size_t read_until(
    SyncReadStream & s,
    boost::asio::basic_streambuf< Allocator > & b,
    MatchCondition match_condition,
    boost::system::error_code & ec,
    constraint_t< is_match_condition< MatchCondition >::value >  = 0);

此函数用于将数据读取到指定的 streambuf,直到用户定义的匹配条件函数对象应用于 streambuf 中包含的数据时,指示成功匹配。调用将阻塞,直到以下条件之一为真

此操作通过零次或多次调用流的 read_some 函数来实现。如果匹配条件函数对象已指示匹配,则函数立即返回。

参数

s

要从中读取数据的流。类型必须支持 SyncReadStream 概念。

b

一个 streambuf 对象,数据将被读取到其中。

match_condition

要调用的函数对象,以确定是否存在匹配。函数对象的签名必须是

pair<iterator, bool> match_condition(iterator begin, iterator end);

其中 iterator 表示类型

buffers_iterator<basic_streambuf<Allocator>::const_buffers_type>

迭代器参数 beginend 定义要扫描的字节范围,以确定是否存在匹配。返回值中的 first 成员是一个迭代器,标记匹配函数已消耗的字节的末尾之后的位置。此迭代器用于计算后续调用匹配条件时的 begin 参数。返回值中的 second 成员如果已找到匹配项,则为 true,否则为 false。

ec

设置为指示发生了什么错误(如果有)。

返回值

streambuf 的 get 区域中已被匹配函数完全消耗的字节数。如果发生错误,则返回 0。

备注

在成功的 read_until 操作之后,streambuf 可能包含超出与函数对象匹配的额外数据。应用程序通常会将该数据留在 streambuf 中,以供后续的 read_until 操作检查。

备注

is_match_condition 类型特征的默认实现对于具有 result_type typedef 的函数指针和函数对象求值为 true。对于其他用户定义的函数对象,必须对其进行特化。


PrevUpHomeNext