简体   繁体   English

c ++,提升asio,慢读

[英]c++, boost asio, slow read

I have slightly modified client code taken from this this example . 我略微修改了此示例中的客户端代码。 The problem I'm having right now is that boost:asio:read call reads really slow, somewhere about 2 bytes per second. 我现在遇到的问题是boost:asio:读取调用读取速度非常慢,大约每秒2个字节。

while (boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error));

or 要么

boost::asio::read(socket, response, boost::asio::transfer_all(), error);

Entire code here 这里有整个代码

I've tried to get a response from different servers, including google.com, got same result, so its neither a server issue nor connection issue. 我试图从不同的服务器获得响应,包括google.com,得到相同的结果,所以它既不是服务器问题也不是连接问题。 Am I doing something wrong? 难道我做错了什么?

Any help will be greatly appreciated. 任何帮助将不胜感激。


Might be related: C++ Boost.ASIO async_read_until slow 可能是相关的: C ++ Boost.ASIO async_read_until slow

The read is not slow, you just forgot to specify the close header: 读取速度不慢,您只是忘了指定关闭标头:

    request_stream << "Connection: close\r\n";

This makes the process swift. 这使得该过程迅速。

Note that the debug output wasn't 'instantaneous' due to buffering, try 请注意,由于缓冲,调试输出不是“瞬时”,请尝试

std::cout.setf(std::ios::unitbuf);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM