使用 boost 的 TCP 零复制 [英] TCP Zero copy using boost

查看:33
本文介绍了使用 boost 的 TCP 零复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 boost 实现 tcp 零复制,但我无法在 google 上找到任何东西.我的问题是是否可以使用 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.

推荐答案

您可以观看 Yandex 人员的 BoostCon 演讲:基于Boost.Asio的网络服务器的优化

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

我的直觉是他们(Yandex 的人)过度设计了这个(相当......).我想说的基本解决方案是仅使用预先分配的固定缓冲区(可能是每个线程),并使用 Asio 的 MutableBufferSequence 概念将它们粘合在一起.

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.

这种方法被称为 Scatter-Gather 并且仅在 Asio 文档中简要描述.这里可能有一个相关的例子:http://www.boost.org/doc/libs/1_56_0/doc/html/boost_asio/examples/cpp11_examples.html#boost_asio.examples.cpp11_examples.buffers

正如@Nim 已经评论过的,Asio 默认在零拷贝"模式下工作(因为它从不拥有缓冲区,也不代表调用者分配).所以让它工作实际上应该非常简单.当然,内核/libc 函数是否以零拷贝方式实现完全取决于操作系统/平台.

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.

这篇关于使用 boost 的 TCP 零复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆