reverbrain/swarm — pull request #22 by iderikon (2014-12-19 10:28:12+00:00)
Title: Buffered_request_stream is reworked.

Please tell me when you are ready to merge pool request, I will up version.

Fixed bug: on_chunk will be called only if client asks next chunk.
Client is considered to wait first chunk after on_request is called.

On_data method is redesigned. The input buffer is handled by loop
according to invariant: m_data is not ready to be processed at the
beginning of each iteration. M_data is ready to be processed means
either m_data size equals to m_chunk_size or m_data contains last
request data.

The iteration of loop is:
If client is ready to get next chunk, we will obtain as much data as we
can, then if m_data is ready to be processed we will call on_chunk.
Otherwise means we is collecting next chunk in background.

Background collecting works as follows:
We will obtain data until either one byte is left to fill the chunk or
one byte is left to obtain last request data. It allows us to initiate
on_data call later, by calling want_more in try_next_chunk, in order to
run on_chunk in thevoid thread.