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:
std::vector<char> buffer;
...
if( ! buffer.empty() )
{
int bytesRead = send( socket, &buffer[ 0 ], buffer.size(), flags );
if( bytesRead > 0 )
buffer.erase( 0, bytesRead );
else
// some error...
}
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?