Search code examples
c++boostioboost-asio

Boost asio reading from the streambuffer after async_read_until stripes spaces


So after I use async_read_until to read until a delimiter there is some extra data that is left in the buffer and I have been trying to read it like this

void Connection::read_left_over(std::string &req, size_t &bytes) {
  std::istream_iterator<char> itr(this->input_stream);
  std::cout << buffer_.in_avail() << std::endl; // returns the size of the data with spaces
  bytes -= size_t(buffer_.in_avail());
  req.append(itr, std::istream_iterator<char>());
  std::cout << buffer_.in_avail() << std::endl; // returns 0
  std::cout << req << std::endl;
}

But the issue is the text that is been read is stripped of spaces, although before reading the buffer says it has a data with spaces and after the read it returns 0. Is there any reason to why this happening and if so a way to overcome this?


Solution

  • This is behaviour of istream. You can get other behaviour using