24 May
2018
24 May
'18
11:53 p.m.
Mere moments ago, quoth I:
Instead of calling async_read with the total number of bytes you are expecting in the message body, first check how many bytes are already available in the streambuf (via size()), and only issue a read for the balance (and if the balance is 0 or negative, then obviously don't issue the read at all).
Also, don't forget to call consume on the streambuf once you have finished using a chunk of data. (ie. after you have read the header size, you need to consume all those bytes so that the remaining size() no longer includes them, before you calculate the balance.)