beast icon indicating copy to clipboard operation
beast copied to clipboard

How to clear recveive buffer after read when buffer is reused.

Open smartseal opened this issue 6 years ago • 3 comments

I am using REST protocol with BEAST https. I try to reuse the beast::buffer::flat_buffer.

But I found each time I send a request and read from http::responsehttp::string_body. the buffer didn't clear the result from previous request. For example, first time the server send back "[]", the second time I read is "[][next time result]".

I called response->clear() and buff->consume(0); it does'nt work.

How to clear the buffer after I have processed the result and prepare the buffer for next time read?

smartseal avatar Jul 15 '19 12:07 smartseal

*msg = {};

See: https://github.com/boostorg/beast/blob/develop/example/http/server/async/http_server_async.cpp#L284

vinniefalco avatar Jul 15 '19 14:07 vinniefalco

I call *response = {}, and it works. Thanks.

I called response->clear() and mbuf->consume() but it doesn't work.

smartseal avatar Jul 16 '19 01:07 smartseal

This needs to be redesigned to be more obvious

vinniefalco avatar Jul 16 '19 03:07 vinniefalco