Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
464 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...