- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个关于使用 boost asio 的 async_read_until 的一般性问题。文档说调用处理程序时缓冲区内可能有更多数据。有没有什么办法可以解决这个问题,并在序列条件匹配后立即阻止缓冲区从套接字中消耗字节?
最佳答案
Q. Is there any way to work around this
不是直接的,因为网络流量的工作方式(它是面向数据包的)。
当然,如果发送方主动确保它,您可能在协议(protocol)边界上得到东西,但这对于流协议(protocol)来说是不寻常的。
Q. and stop the buffer from consuming bytes from the socket right after the sequence condition was matched?
不,但是您可以停止使用缓冲区。所以,例如这是一个有效的模式:
boost::asio::streambuf sb;
auto bytes = boost::asio::read_until(socket, sb, "\r\n\r\n");
std::istream is(&sb);
std::string line;
while (getline(is, line) && !line.empty()) {
std::cout << "Received: '" << line << "'\n";
}
// sb still contains un-consumed data, if any
只需对任何后续读取使用相同的 streambuf
,它将为您管理“流位置”。
关于c++ - Boost asio async_read_until 在匹配条件下停止阅读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46846949/
我正在尝试使用 boost asio 库来实现网络编程。这是当一些数据(以“##”结尾)到达端点时调用的代码。 { boost::asio::async_read_until(m_socket
我在此处记录的函数中实现第三个参数时遇到问题: http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/reference/async_rea
我在使用 async_read_until 时遇到问题。我最初使用的是 async_receive,但我的服务器的响应增长到不止一个数据包,我遇到了一个问题,即 async_receive 在收到第一
我正在尝试使用 boost::shared_ptr与 async_read_until并且无法让它工作。这是我的简化代码: 标题 boost::asio::io_service io_service;
我正在使用带有 '\n' 分隔符的 asio::async_read_until 来支持从服务器获取字符数据的 TCP 客户端。此服务器不断发送 '\n' 终止行;准确地说,它可以同时写入单行或多行的
在 boost::asio::async_read_until 之后,我面临周期性的无限等待处理程序调用。这出现在两种情况下: 在服务器上,尽管客户端 boost::asio::async_write
我正在尝试将 c++11 lambda 与 boost::asio::async_read_until 一起使用,如下所示: void TCPSession::readData() { auto
我正在尝试使用自定义匹配函数作为 boost::asio 组合操作的一部分。当传入 std::move(*this) 作为异步操作的处理程序时,VS2017 无法使用自定义匹配条件推断参数。 组合操作
我想知道如何限制使用 async_read_until 读取的字节大小。从现在开始,我将它与定界符字符一起使用,但我想更改。这是我所做的: void Client::doRead()
我正在学习如何将 Boost:asio 库与串行端口一起使用。我使用同步写入和读取编写了一些代码,现在我想使用异步,但它不起作用。简单示例: void readHandler(const boost:
我正在尝试修改来自 boost asio 的 echo 服务器示例,当我尝试使用 boost::asio::async_read_until 时遇到了问题。这是代码: #include #i
我遇到了一个不寻常的问题。我有一个 C++ Boost.ASIO 网络服务器,为了处理传入的请求,我正在使用以下代码: boost::asio::async_read_until( socke
我有一个关于使用 boost asio 的 async_read_until 的一般性问题。文档说调用处理程序时缓冲区内可能有更多数据。有没有什么办法可以解决这个问题,并在序列条件匹配后立即阻止缓冲区
我正在尝试在本地网络上的两台计算机之间建立连接,一台使用 Boost Asio C++ TCP 异步服务器示例的略微修改版本,另一台使用 NodeJS。 tcp_client.js : var net
我正在从串行设备读取,其中必须特别请求每条消息。例如。您发送请求并获得带有序列化负载的响应。 每条消息按顺序包含这些部分: 序言(2 字节,“$M”) HEADER(3字节,包含有效载荷长度N) 有效
有没有办法结合两个条件读取,直到找到匹配字符或收到 128 个字节? 可以限制 streambuf 的大小: inBuf = std::make_shared(limit_size); 但是当处理程序
我正在使用以下方法: boost::asio::streambuf io_bufstream; boost::asio::async_read_until(socket_, io_bufstream,
我正在用 boost asio 制作一个 Irc 机器人,我在编译它时遇到了一些问题,而且错误不是真正可读的。 似乎其中一个async_read_until进行得不是很好,但我不知道为什么。 这是 g
我使用了来自 boost 的异步 tcp 服务器示例,它与我的应用程序正在做的很接近。下面的代码示例是一个完整的示例。 首先,我开始异步读取操作,直到分隔符 char。在这种情况下,它是 http h
我正在修改 Boost Asio 回显示例以使用 async_read_until 逐字读取输入。即使我使用 async_read_until,所有发送的数据似乎都是从套接字读取的。有人可以建议: #
我是一名优秀的程序员,十分优秀!