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.
-
3`boost::asio` is zero copy in that it will not copy the buffers you pass through it. However whether zero copy operations will be used through the tcp stack - that's a different issue.. – Nim Sep 01 '14 at 08:14
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.

- 374,641
- 47
- 450
- 633