结合sendo()写writev()吗? [英] Combining sento() write writev()?

查看:80
本文介绍了结合sendo()写writev()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个udp套接字,并在每次调用时使用不同的收件人调用sendto().

I've set a udp socket and call sendto() with a different recipient at each call.

我想使用writev()来使scater/gather io受益,但是writev()不允许我像sendto()一样指定接收者地址/端口.有什么建议吗?

I would like to use writev() in order to benefit scater/gather io but writev() does not allows me to specify the recipient addr/port as in sendto(). Any suggestions?

推荐答案

您可以使用 writev 将一组合并的缓冲区发送到单个端点(如果使用) connect 可以预先指定终点.在 connect(2)的(OSX)联机帮助页中:

You can use writev to send a coalesced set of buffers to a single end point if you use connect to specify the end point beforehand. From the (OSX) manpage for connect(2):

数据报套接字可能多次使用connect()来更改其关联

datagram sockets may use connect() multiple times to change their association

不能使用 writev 将每个缓冲区发送到不同的端点.

You cannot use writev to send each buffer to a different endpoint.

使用 connect/writev 而不是 sendto * n 的潜在缺点是,这是每个 writev的另一个系统调用.

A potential downside of using connect / writev instead of sendto*n is that it is yet another system call per writev.

如果一组收件人有限(并且事先知道),则最好为每个收件人使用一个单独的 socket ,而每个套接字仅 connect 个.

If the set of recipients is limited (and known in advance) it may be preferable to use a separate socket per recipient and just connect each socket once.

这篇关于结合sendo()写writev()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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