Quote Originally Posted by ChrisW67 View Post
Every byte that a QIODevice/QTCPSocket accepts for sending will be sent barring abnormal termination. That is not to say that every byte offered will be accepted for sending, i.e. QIODevice::write() may return a positive number smaller than the number of bytes offered. You have to handle that if it is likely to apply. I've never seen it myself, but I only send short messages generally.

I read your initial question as if you were trying to coopt the TCP windowing mechanisms. I think waiting until all the bytes accepted have been sent before offering more bytes is sub-optimal. You are waiting for an empty buffer rather than trying to keep the send buffer near-full. By keeping the send buffer near-full you ensure that Qt and OS can operate normally with respect to the throughput regulation mechanisms in TCP. You might like to add more data to the queue every time bytesSent() is received, or only after x KB are sent (an adaptation of your original suggestion).
The thing is, I also have just relatively short packages to send. But I want to be 100% sure they are actually sent, so the two options are either what I originally wrote, or loop on ::write until it reports all send. The latter doesn't play with the GUI event loop well.

Perhaps my approach is an overkill, but it will only be triggered in very rare cases so maybe that's not too bad?