I am using boost::asio::async_read_until
to read the \n
-ended line from the TCP socket. Let me please recall that async_read_until
signature is the following:
void-or-deduced async_read_until(
AsyncReadStream & s,
boost::asio::basic_streambuf< Allocator > & b,
char delim,
ReadHandler handler);
Here
boost::asio::streambuf b;
is auto resized object to store received data.
As far as I understand, it internally consists of buffer sequence, a list of boost::asio buffers. However, there is no easy way to obtain ForwardIterator to iterate over this internal buffer that consists of multiple contiguous regions.
I find the following usage pattern:
std::istream stream(&b);
std::istream_iterator<char> end;
std::istream_iterator<char> begin(stream);
However, here end
and begin
are InputIterators.
At the same time, boost::spirit::phrase_parse(begin, end, grammar, space, obj)
parser that could be used to parse obtained from socked line requires begin
and end
be ForwardIterators:
http://www.boost.org/doc/libs/1_63_0/libs/spirit/doc/html/spirit/support/multi_pass.html
This is required for backtracking. However, the data are actually already stored in the memory buffer in boost::asio::streambuf b
object, nothing prevents iterator from being dereferenced more than once.