title: How to turn off TCP PSH flag in the POSIX function send()?
body: <p>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.</p>
  
  <p>A screenshot of Wireshark showing the use of the PSH flag by my code:</p>
  
  <p><a href="https://i.stack.imgur.com/6oRJl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6oRJl.png" alt="enter image description here"></a>
  <br></p>
  
  <p>I am using C++11 which is running in Ubuntu (16.04).</p>
  
  <p>My send function looks like so:</p>
  
  <pre><code>int sendStatusCode = send(socket , *&amp;pointerToMessageAsCharArray , sizeOfMessage , 0);
  </code></pre>
  
  <p>I looked over <a href="https://linux.die.net/man/2/send" rel="nofollow noreferrer">the writeup</a> 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?</p>
  
  <p><strong>Edit</strong>
  The size of the messages is quite small. for example:
  <code>const char m_ME[5] = {m_HEADER_ONE, m_HEADER_TWO, m_M_HEX, m_E_HEX, m_FOOTER_HEX};</code></p>
  
  <p>which when sent looks like so:
  <a href="https://i.stack.imgur.com/MZehJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MZehJ.png" alt="enter image description here"></a></p>
  
  <p>The largest message I am sending is 8 chars which works out to 8 bytes.</p>
  
  <p><strong>EDIT</strong>
  I implemented this answer (<a href="https://stackoverflow.com/questions/17842406/how-would-one-disable-nagles-algorithm-in-linux">How would one disable Nagle&#39;s algorithm in Linux?</a>) and it looks to me that TCP_NODELAY does not turn off the PSH flag. The code I used to check:</p>
  
  <pre><code>int noDelayState = 1; // 0 means prefer bandwidth optimization over low latency
  
  int tcpPushOptionOff = setsockopt(m_socketRight
      , IPPROTO_TCP
      , TCP_NODELAY
      ,(char *) &amp;noDelayState
      , sizeof(int));
  
  if (tcpPushOptionOff &lt; 0) { /* do smth */ }
  </code></pre>