1

I'm would like to receive directly into a boost::lockfree:spsc_queue (or, alternatively, a boost::circular_buffer) from a boost::asio::async_read call. Looks like I need to write a wrapper to make the spsc_queue a MutableBuffer.

Can anyone share some guidance on if this is possible, and how to achieve this?

Many thanks

schuess
  • 1,009
  • 1
  • 10
  • 21

1 Answers1

3

Each receive buffer must be contiguous when using asio.

Since boost::circular_buffer is not contiguous it is rather inconvenient to use as a byte buffer. Still, though, you can present it to asio as 2 buffers with scatter-gather I/O.

An efficient and convenient circular buffer for I/O is a region of memory pages mapped twice without any padding between them. This way you can read into your circular buffer with one read syscall, without having to use scatter-gather I/O and without having to deal with buffer discontinuity when parsing/reading its contents.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271