schuess
schuess

Reputation: 1059

boost::lockfree::spsc_queue and boost::asio

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

Upvotes: 1

Views: 481

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136256

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.

Upvotes: 3

Related Questions