Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCP Zero copy using boost

I am trying to implement tcp zero copy using boost but i am not able to find anything on google .My question is it possible to perform zero copy using boost libraries and if so please send me some example or some link.

like image 305
Rsvay Avatar asked Sep 01 '14 08:09

Rsvay


1 Answers

You could watch this BoostCon talk by the Yandex guys: The Optimization of a Boost.Asio-based Networking Server

My gut feeling says they (the Yandex guys) overengineered this (quite a bit...). I'd say the essential solution would lie in just using pre-allocated fixed-buffers (perhaps per-thread) and use the MutableBufferSequence concept from Asio to glue them together.

This approach is known as Scatter-Gather and is only briefly described in the Asio docs. There could be a relevant example here: http://www.boost.org/doc/libs/1_56_0/doc/html/boost_asio/examples/cpp11_examples.html#boost_asio.examples.cpp11_examples.buffers

As @Nim already commented, Asio by default works in "zero-copy" mode (because it never owns a buffer, nor allocates on behalf of the caller). So it should actually be pretty simple to get it to work. Of course, whether the kernel/libc functions are implemented in zero-copy fashion depends solely on the OS/platform.

like image 51
sehe Avatar answered Nov 16 '22 07:11

sehe