C - 仅在 MTU 达到最大值时才发送 TCP 数据包

标签 c networking tcp mtu

是否有任何内置功能(标志、参数等)仅在其 MTU(几乎)满时才发送 TCP 数据包?

我希望我的假设是正确的,数据总是被发送并且它包含多少有效负载并不重要(试图通过 wireshark 找到它)。

最好的问候

最佳答案

I hope I'm right with my assumption, that data is sent always

不,TCP 堆栈通常会捆绑数据并发送大段(但它不会永远等待,通常只是一小会儿)- 通常 Nagles algorithm或者使用了一些变体。

可能还有其他问题会影响数据的缓冲和发送方式,例如网络有多拥挤。通常,TCP 堆栈非常擅长实现最大吞吐量,通常您不应该试图超越它。

如果您需要更低的延迟,您可以通过设置 TCP_NODELAY 套接字选项来禁用 Nagle 的算法

int ndelay = 1;
setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char *)&ndelay ,sizeof(ndelay));

Linux 也通过 TCP_CORK 提供了相反的结果,也许更接近您的要求。

TCP_CORK If set, don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. As currently implemented, there is a 200 millisecond ceiling on the time for which output is corked by TCP_CORK. If this ceiling is reached, then queued data is automatically transmitted. This option can be combined with TCP_NODELAY only since Linux 2.5.71. This option should not be used in code intended to be portable.

关于C - 仅在 MTU 达到最大值时才发送 TCP 数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4924808/

相关文章:

C 错误 : expected expression before ‘{’ token

c++ - 如何枚举所有可用的网络接口(interface)?

c# - 将 TcpClient ReceiveTimeout 与同步程序一起使用

c - 关于栈溢出的练习

c++ - 进程内存映射(Linux Windows)

go - 尝试从Gitea连接到AD服务器时出错

Python 客户端 - C++ 服务器连接被拒绝错误

java - 停止我的 TCP 服务器 java 时抛出 SocketException

spring-boot - Spring集成TCP客户端抛出 'Socket closed during message assembly'异常

c - X11: 将像素值转换为 RGB