The principle is called scatter/gather IO . In principle, a way to transfer several buffers at once (in order), without expensive memory copying. It is well supported in boost :: asio with a very flexible and powerful (but also hard to understand) buffer concept and buffer sequence concept.
A simple (untested, but I think is correct) example to get you started would be:
std::vector<boost::asio::streambuf::const_buffers_type> buffers; buffers.push_back( my_first_streambuf.data() ); buffers.push_back( my_second_streambuf.data() ); std::size_t length = boost::asio::write( mySocket, buffers );
Of course, one simple option would be to just read both posts in streambuf and just send the whole streambuf, but from your question, I assume this is not an option for some reason?
source share