When does a UDP sendto() block?

前端 未结 2 1483
孤城傲影
孤城傲影 2020-12-13 00:31

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.

For TCP

2条回答
  •  一个人的身影
    2020-12-13 01:15

    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.

    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.

提交回复
热议问题