質問

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.

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. Am I doing something wrong?

Any help will be greatly appreciated.


Might be related: 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帰属
所属していません StackOverflow
scroll top