使用单个 send() 调用发送多个数据报?

发布于 2024-07-15 00:20:34 字数 84 浏览 7 评论 0原文

当基于数据报的套接字(原始套接字或 UDP)与收集式发送一起使用时,所有数据都会连接起来形成单个 IP 数据包。 有没有办法使用一次调用发送多个数据报?

When datagram-based socket (raw socket or UDP) is used with gather-style send, all the data are concatenated to form a single IP packet. Is there a way to send several datagrams using a single call?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把梦留给海 2024-07-22 00:20:34

您所问的问题有点有趣,因为正如名称所示,gather-style send() 从内存中的多个位置收集数据并将其放入一个缓冲区中,然后发送。

因此,您有多个数据部分想要发送多个数据报。 为什么不通过单独的呼叫发送来发送它们?

实际上,您可以在数据报套接字上调用 connect() 来指定默认目标,这样您就可以 send() 或 write() 而无需每次都指定目标地址。

What you are asking is a bit funny since gather-style send() as the name says gathers data from multiple places in memory and puts it together into one buffer which it then sends.

So you have multiple parts of data you want to send multiple datagrams. Why don't you send them with separate calls to send?

You can actually call connect() on a datagram socket to specify a default target so you can can send() or write() without specifying the destination address each time.

如果没结果 2024-07-22 00:20:34

我不这么认为...您希望 IP 堆栈如何推断您想要数据包数据报的位置?

I don't think so ... How would you expect the IP stack to infer where you intend the packet datagram to be?

零度℉ 2024-07-22 00:20:34

您正在寻找的调用是 sendmmsg() 但它尚未实现,甚至还没有进行太多讨论。 在最新的2.6中可以看到它的接收端双胞胎 recvmmsg() .3 Linux 内核。

The call you are looking for is sendmmsg() however it is not yet implemented or even up for much discussion. You can see it's receive side twin recvmmsg() in the latest 2.6.3 Linux kernel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文