UDP sendto() 何时阻塞? [英] When does a UDP sendto() block?

查看:13
本文介绍了UDP sendto() 何时阻塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 UDP 套接字上使用默认(阻塞)行为时,在这种情况下,对 sendto() 的调用会阻塞吗?我主要对 Linux 行为感兴趣.

While using the default (blocking) behavior on an UDP socket, in which case will a call to sendto() block? I'm interested essentially in the Linux behavior.

对于 TCP,我知道如果发送窗口已满,拥塞控制会使 send() 调用阻塞,但是 UDP 呢?它有时甚至会阻塞或只是让数据包在较低层被丢弃?

For TCP I understand that congestion control makes the send() call blocking if the sending window is full, but what about UDP? Does it even block sometimes or just let packets getting discarded at lower layers?

推荐答案

如果您填满了套接字缓冲区,可能会发生这种情况,但它高度依赖于操作系统.由于 UDP 不提供任何保证,当您的套接字缓冲区已满时,您的操作系统可以决定做任何事情:阻塞或丢弃.您可以尝试增加 SO_SNDBUF 来临时缓解.

This can happen if you filled up your socket buffer, but it is highly operating system dependent. Since UDP does not provide any guarantee your operating system can decide to do whatever it wants when your socket buffer is full: block or drop. You can try to increase SO_SNDBUF for temporary relief.

这甚至可能取决于系统的微调,例如,它还可能取决于网络接口驱动程序中 TX 环的大小.iperf 邮件列表,但您确实想与您的操作系统的开发人员讨论这个问题.特别注意 O_NONBLOCK 和 EAGAIN/EWOULDBLOCK.

This can even depend on the fine tuning of your system, for instance it can also depend on the size of the TX ring in the driver of your network interface. There are a few discussions about this in the iperf mailing list, but you really want to discuss this with the developers of your operating system. Pay special attention to O_NONBLOCK and EAGAIN / EWOULDBLOCK.

这篇关于UDP sendto() 何时阻塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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