In the Chat example of the library, I see that there is a "chat_message" header declaring a class. In that class, I can see the following functions -among others-:
const char* body() const
{
return data_ + header_length;
}
char* body()
{
return data_ + header_length;
}
std::size_t body_length() const
{
return body_length_;
}
I only see accessors here, no mutators. However, in the "chat_session" class, the handlers make use of this class even if it does not have any mutators. However, I guess that the member variables of "chat_message" are modified somehow. See this piece of code from "chat_session":
void handle_read_header(const boost::system::error_code& error)
{
if (!error && read_msg_.decode_header())
{
boost::asio::async_read(socket_,
boost::asio::buffer(read_msg_.body(), read_msg_.body_length()),
boost::bind(&chat_session::handle_read_body, shared_from_this(),
boost::asio::placeholders::error));
}
else
{
room_.leave(shared_from_this());
}
}
void handle_read_body(const boost::system::error_code& error)
{
if (!error)
{
room_.deliver(read_msg_);
boost::asio::async_read(socket_,
boost::asio::buffer(read_msg_.data(), chat_message::header_length),
boost::bind(&chat_session::handle_read_header, shared_from_this(),
boost::asio::placeholders::error));
}
else
{
room_.leave(shared_from_this());
}
}
I guess that in the "async_read"s the received data is passed somehow to the object, but I don't understand how.
Could you explain to me how is data passed from the "async_read" to the object?
Thank you very much indeed.