On Linux (Kernel 3.0.0.12; C++ with GCC 4.6.1) I want to send shortly after each other a few TCP-packets via (POSIX) send-call.
With Wireshark I can see that the packets weren’t sent in separate TCP-frames, but two or more were sent together in one packet.
Is there any way to tell the system to send data from one send()-buffer in own TCP-packet? The programmflow shouldn’t block at the send-call.
Your TCP stack is implementing Nagle’s algorithm trying to increase efficiency by buffering data. Its a common optimization where the intent is amortize the cost of the 40+ byte (TCP + IP) header. Instead of sending multiple small packets, the stack buffers the data and combines them into a larger packet thereby reducing the header overhead.
TCP stacks don’t buffer indefinitely though. As long as there is some un-acknowledged sent data on the connection, the sender continues to buffer. The next packet is sent out when:
You can usually disable this by setting the
TCP_NODELAYsocket option.