I'm using Boost.Asio for a server application that I'm writing.
async_send
requires the caller to keep ownership of the data that is being sent until the data is sent successfully. That means my code (which looks like the following) will fail, and it does, because data
will no longer be a valid object.
void func()
{
std::vector<unsigned char> data;
// ...
// fill data with stuff
// ...
socket.async_send(boost::asio::buffer(data), handler);
}
So my solution was to do something like this:
std::vector<unsigned char> data;
void func()
{
// ...
// fill data with stuff
// ...
socket.async_send(boost::asio::buffer(data), handler)
}
But now I'm wondering if I have multiple clients, will I need to create a separate vector for each connection?
Or can I use that one single vector? If I'm able to use that single vector, if I overwrite the contents inside it will that mess up the data I'm sending to all my clients?