As of right now (Boost 1.66), it is not possible to read data into boost::circular_buffer
because it doesn't expose any way to reserve space in the underlying buffer, which is a requirement for creating a mutable_buffer
needed to call asio::read
.
But it is possible to write from boost::circular_buffer
:
boost::circular_buffer<char> cir_buf;
FillBuffer(cir_buf);
// Construct a buffer sequence with either 1 or 2 data chunks
std::vector<boost::asio::const_buffer> buffer_sequence;
auto arr1 = cir_buf.array_one();
buffer_sequence.push_back(boost::asio::buffer(arr1.first, arr1.second));
auto arr2 = cir_buf.array_two();
if (arr2.second != 0) {
buffer_sequence.push_back(boost::asio::buffer(arr2.first, arr2.second));
}
boost::asio::write(socket_, buffer_sequence);
circular_buffer
:array_one
,array_two
,rotate
andlinearize
. You can usearray_one()
andarray_two()
to get internal buffers(slices of one big buffer) and feedboost::asio::buffer
with them. – Siliceousarray_one
andarray_two
. – Vassauxasync_write
? – Darr