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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With