Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] continuous reads into streambuf
From: Vinnie Falco (vinnie.falco_at_[hidden])
Date: 2018-05-24 18:18:01


On Thu, May 24, 2018 at 10:49 AM, Stephan Menzel via Boost-users
<boost-users_at_[hidden]> wrote:
> This pretty much means taking over what asio calls 'composed operations'

You don't have to write a composed operation and accompanying
initiating function, you can do this right in the code you already
have. Just replace `async_read_until` with `stream.async_read_some`
and put that in a loop.

> ...I always folded when it came to
> inspecting the contents of a streambuf. I simply don't know how this can be
> done.

There are a few approaches. The easiest solution is to convert the
readable bytes of the stream buffer to a pair of iterators using these
asio utility functions, and apply std algorithms (or your own) to that
range:

<https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/reference/buffers_begin.html>
<https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/reference/buffers_end.html>

If you are using Boost.Asio 1.67, you can adapt a std::string into a
dynamic buffer using dynamic_string_buffer:

<https://www.boost.org/doc/libs/1_67_0/doc/html/boost_asio/reference/dynamic_string_buffer.html>

Once you have the message in a std::string it should be pretty
straightforward to use string algorithms on it.

Hope this helps!


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net