While a send() succeeds with all data being sent most of the time, it is not always the case. Thus people are advised to use the write-fdset for select() and poll() to check when the socket is writeable.
How do usual mechanisms look like to actually buffer the data to send while still maintaining a well comprehensible sourcecode?
As we’re in C++ land, you could store the data in a std::vector
New data gets appended to the end of the vector. When you get notification that the socket is writable, try to send the complete vector. send() will return how much was really sent. Then simply erase that number of bytes from the beginning of the vector:
So there’s probably more error checking to do, but you get the idea?
Rather queueing each individual send request, the advantage here is that you get to potentially combine multiple higher level sends into one socket send, assuming you’re using TCP?
But as Remus quite rightly mentions, your flow control and API is the tricky bit – i.e. how do you stop the buffer becoming too big?