mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
fix(network): send message length before body
This commit is contained in:
@@ -19,10 +19,10 @@ namespace UNO::NETWORK {
|
|||||||
|
|
||||||
void Session::send(const std::string &message)
|
void Session::send(const std::string &message)
|
||||||
{
|
{
|
||||||
auto buffer = std::make_shared<std::string>(message);
|
auto length = std::make_shared<size_t>(message.size());
|
||||||
asio::async_write(socket_, asio::buffer(*buffer), [this, self = shared_from_this(), buffer](const asio::error_code &ec, size_t) {
|
auto msg = std::make_shared<std::string>(message);
|
||||||
if (ec) {}
|
std::array<asio::const_buffer, 2> buffers = {asio::buffer(length.get(), sizeof(size_t)), asio::buffer(*msg)};
|
||||||
});
|
asio::async_write(socket_, buffers, [this, self = shared_from_this(), length, msg](const asio::error_code &ec, size_t) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::read()
|
void Session::read()
|
||||||
|
|||||||
Reference in New Issue
Block a user