Mik*_*ike 7 c++ posix tcp send nagle
I am sending commands to a stepper motor system using Ethernet. The commands get the motor to move, or respond with drive status, or configure the drive, etc... The stepper motor system sometimes hangs, or fails to execute the command, and the manufacturer having looked over everything I supplied has told me to turn off the PSH flag in the TCP layer.
A screenshot of Wireshark showing the use of the PSH flag by my code:
I am using C++11 which is running in Ubuntu (16.04).
My send function looks like so:
int sendStatusCode = send(socket , *&pointerToMessageAsCharArray , sizeOfMessage , 0);
Run Code Online (Sandbox Code Playgroud)
I looked over the writeup for the function, and I understand that the last argument (which I have at 0) is a flag. What I do not understand is the value that I need to plug in to turn off the PSH flag without changing anything else (if that is even possible). Can you help?
Edit
The size of the messages is quite small. for example:
const char m_ME[5] = {m_HEADER_ONE, m_HEADER_TWO, m_M_HEX, m_E_HEX, m_FOOTER_HEX};
which when sent looks like so:

The largest message I am sending is 8 chars which works out to 8 bytes.
EDIT I implemented this answer (How would one disable Nagle's algorithm in Linux?) and it looks to me that TCP_NODELAY does not turn off the PSH flag. The code I used to check:
int noDelayState = 1; // 0 means prefer bandwidth optimization over low latency
int tcpPushOptionOff = setsockopt(m_socketRight
, IPPROTO_TCP
, TCP_NODELAY
,(char *) &noDelayState
, sizeof(int));
if (tcpPushOptionOff < 0) { /* do smth */ }
Run Code Online (Sandbox Code Playgroud)
使用标准 Linux TCP 堆栈,您无法直接控制它。是否设置 PSH 标志由发送缓冲区和堆栈中的副本控制。借助嵌入式 LWIP 堆栈之类的东西,您可以拥有更多控制权。
但是,尝试将 setsockopt(SO_SNDBUF) 设置为一个非常小的值,看看这是否会产生影响。小于数据包大小,即几个字节缓冲区大小设置不起作用,因为操作系统强制执行大于帧的最小大小。
| 归档时间: |
|
| 查看次数: |
282 次 |
| 最近记录: |