无法关闭TCP_NODELAY [英] Can't turn TCP_NODELAY OFF

查看:697
本文介绍了无法关闭TCP_NODELAY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Boost asio发送TCP消息.我设置了NO_DELAY选项,因为这是一个实时"控制系统.我使用Wireshark看到消息中设置了PSH标志.我对性能感到满意,并且按预期运行.

I'm using Boost asio to send a TCP message. I set the NO_DELAY option because this is a 'real time' control system. I see the PSH flag set in the message using Wireshark. I am happy with the performance and it is working as expected.

出于兴趣,我决定关闭NO_DELAY并测量性能差异.

For interest, I decided to turn the NO_DELAY off and measure the performance difference.

我交换了现有代码:

m_tcpSocket.open(boost::asio::ip::tcp::v4());
boost::asio::ip::tcp::no_delay noDelayOption(true);
m_tcpSocket.set_option(noDelayOption);

// snip create endpoint
m_tcpSocket.connect(m_tcpServerEndpoint);

// snip build message
m_tcpSocket.send(boost::asio::buffer(pDataBuffer, size));

对于

boost::asio::ip::tcp::no_delay noDelayOption(false);
m_tcpSocket.set_option(noDelayOption);

并且我仍然看到设置了PSH标志.

and I still see the PSH flag set.

我还尝试删除了set_option代码,但仍然看到它已设置.

I also tried removing the set_option code and still see it set.

在Wireshark中,我看到了:

In Wireshark I see:

104 - 105  SYN
105 - 104  SYN, ACK
104 - 105  ACK
104 - 105  PSH, ACK + my message
105 - 104  ACK

其中104和105是我的2台PC的IP地址. 对于包含我的数据的消息具有ACK,我也感到惊讶.

where 104 and 105 are IP addresses of my 2 PCs. I am also surprised that the message with my data has an ACK.

如何关闭NO_DELAY?

How do I turn NO_DELAY off?

推荐答案

您的代码似乎正确设置了TCP_NODELAY的打开或关闭状态.要关闭TCP_NODELAY,请使用:

Your code looks as though it is properly setting TCP_NODELAY on or off. To set TCP_NODELAY off, use:

socket.set_option(boost::asio::ip::tcp::no_delay(false));

TCP RFC 将PSH定义为推送功能.简而言之,它是一个标志,通知接收器所有数据都已发送,因此将数据转发到协议栈. Boost.Asio 地图其BSD套接字的API和BSD套接字不提供控制PSH标志的方法.协议栈中的内核通常会在清除缓冲区时对其进行处理.

The TCP RFC defines PSH as the push function. In short, it is a flag that informs the receiver that all data has been sent, so forward data up the protocol stack. Boost.Asio maps its API to BSD sockets, and BSD sockets do not provide a way to control the PSH flag. This is often handled by the kernel within the protocol stack, when it clears its buffer.

来自 TCP/IP说明:

该标志通常用于指示发送数据包一侧的缓冲区已与发送数据包一起被清空.换句话说,当设置了PSH位字段的数据包离开发送方时,发送方将没有更多数据要发送.

This flag is conventionally used to indicate that the buffer at the side sending the packet has been emptied in conjunction with sending the packet. In other words, when the packet with the PSH bit field set left the sender, the sender had no more data to send.

[...]

推送(接收方应尽快将这些数据传递给应用程序-不能可靠地实现或使用).

Push (the receiver should pass this data to the application as soon as possible—not reliably implemented or used).

这篇关于无法关闭TCP_NODELAY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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