boost::asio::read_until reads too much!
executing this code: boost::asio::streambuf b; std::cout << "socket.available()=" << socket.available() << std::endl; size_t received = boost::asio::read_until(socket, b, "\r\n"); std::cout << "received=" << received << std::endl; std::cout << "b.size()=" << b.size() << std::endl; std::istream is(&b); std::getline(is, m_token); results in output of: socket.available()=34 received=26 b.size()=34 In my app I need to read the 8 bytes (after the 26) as binary (and hence don't use the streambuf to do so). Yet read_until has already consumed them from the socket and placed them in the streambuf :( Suggestions?
"Rob Currey"
In my app I need to read the 8 bytes (after the 26) as binary (and hence don't use the streambuf to do so). Yet read_until has already consumed them from the socket and placed them in the streambuf :(
Suggestions?
Can you just pull the raw bytes directly from the streambuf? It should contain the bytes that were sent; as far as I know it doesn't do any translation or change them at all. ----Scott.
From: "Igor R"
Suggestions?
For the both readings use the same buffer - either streambuf or any other.
Yea, I figured that might be the case, but also means I can't use boost::asio::read_until for this purpose. I mistakenly thought that: boost::asio::streambuf b; boost::asio::read_until(socket, b, "\r\n"); would actually STOP consuming from the socket when it got the "\r\n" ... The documentation seems to imply this: "This function is used to read data into the specified streambuf *until* the streambuf's get area contains the specified delimiter." (emphasis on *until* mine) In reality it will read more than that into the streambuf ... I'm reworking my implementation to have my own buffer (not streambuf based) and then implement my own "read_until" ...
In reality it will read more than that into the streambuf ...
I'm reworking my implementation to have my own buffer (not streambuf based) and then implement my own "read_until" ...
I guess, the only way to really read *until* is to read char-by-char (which might be very inefficient) isn't it?
participants (3)
-
Igor R
-
Rob Currey
-
Scott Gifford