简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM